I want to do a Qt binding for FB

General discussion for topics related to the FreeBASIC project or its community.
miilvyxg
Posts: 193
Joined: Dec 07, 2021 6:51

I want to do a Qt binding for FB

Post by miilvyxg »

What should I do? A complete translation of the Qt headers is impossible. At most, we can only translate the part we actually used. Anyone wanted to have Qt backend for your GUI library?

I want to hear from Window9 developer and MyFbFramework developer if they are interested. This is just finding a purpose to push me go further. My competent and ability is very limited. I have no idea how long I could go.
Xusinboy Bekchanov
Posts: 783
Joined: Jul 26, 2018 18:28

Re: I want to do a Qt binding for FB

Post by Xusinboy Bekchanov »

miilvyxg wrote:What should I do? A complete translation of the Qt headers is impossible. At most, we can only translate the part we actually used. Anyone wanted to have Qt backend for your GUI library?

I want to hear from Window9 developer and MyFbFramework developer if they are interested. This is just finding a purpose to push me go further. My competent and ability is very limited. I have no idea how long I could go.
If there were bindings, it would be nice.
There are attempts here too:
viewtopic.php?f=8&t=15187&start=15
miilvyxg
Posts: 193
Joined: Dec 07, 2021 6:51

Re: I want to do a Qt binding for FB

Post by miilvyxg »

Xusinboy Bekchanov wrote:
miilvyxg wrote:What should I do? A complete translation of the Qt headers is impossible. At most, we can only translate the part we actually used. Anyone wanted to have Qt backend for your GUI library?

I want to hear from Window9 developer and MyFbFramework developer if they are interested. This is just finding a purpose to push me go further. My competent and ability is very limited. I have no idea how long I could go.
If there were bindings, it would be nice.
There are attempts here too:
viewtopic.php?f=8&t=15187&start=15
Could we just reuse the code of Gambas3? I found their approach is simple yet elegant. But due to being an incompetent dude I can't duplicated it for FB. Even though I found it's beautiful implemented yet I'm not really understand it enough.

https://gitlab.com/gambas/gambas/-/tree/master/gb.qt4

https://gitlab.com/gambas/gambas/-/tree/master/gb.qt5
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: I want to do a Qt binding for FB

Post by D.J.Peters »

First you can't link the MinGW QT C++ classes and use the exported GUI widget directly with FreeBASIC !

You have to write in C++ your own classes that wraps the primary QT properties and callback slots and export it as "simple C++" object or export the functionality via ordinary C interface !

I wrote the most C++ wrappers for FreeBASIC in the past there are to many pitfalls to use external "complex C++" classes direct with FreeBASIC.

Joshy
miilvyxg
Posts: 193
Joined: Dec 07, 2021 6:51

Re: I want to do a Qt binding for FB

Post by miilvyxg »

D.J.Peters wrote:First you can't link the MinGW QT C++ classes and use the exported GUI widget directly with FreeBASIC !

You have to write in C++ your own classes that wraps the primary QT properties and callback slots and export it as "simple C++" object or export the functionality via ordinary C interface !

I wrote the most C++ wrappers for FreeBASIC in the past there are to many pitfalls to use external "complex C++" classes direct with FreeBASIC.

Joshy
Yeah, I know. The links to Gambas's code above is also follows the same principle. The problem is Qt is too big so it's unpractically to cover all of the APIs of it. I have no idea which parts of Qt the FB library developers would use. And doing the translation by hand seems almost impossible, too. People all use some kinds of automatic translator to generate the bindings:

https://github.com/OmixVisualization/qtjambi

https://gitlab.com/ddobrev/QtSharp

The people of Gambas could do the thing by hand, though. The reason I think it's this way because their binding code is extremely limited, covering only the most essential parts that they need. Their approach is very simple yet elegant. Their code is beautiful. This is the reason why I think if we could reuse their code by extending it to cover what we need or at least do our own but follow the same pattern.

The Gambas people's way is the most practical for us to learn from since we have no powerful translator to generate the binding automatically.
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: I want to do a Qt binding for FB

Post by VANYA »

For me, QT is not interesting. Freebasic has enough available tools to do whatever you want without the QT library.
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: I want to do a Qt binding for FB

Post by marcov »

Another attempt at flattening by the Lazarus people:
original outdated site: http://users.telenet.be/Jan.Van.hijfte/ ... pcqt4.html

current maintainer of qt5 lib: https://github.com/davidbannon/libqt5pa ... tag/v1.2.9
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: I want to do a Qt binding for FB

Post by caseih »

Yes it would be possible to create bindings for Qt using some of the same tools that are used to create bindings for other languages. There a few automated tools such as SWIG. Such tools are used to create the Qt sharp bindings, python bindings, etc. However the process is very complex. Better than doing it all by hand, which was way we used to do it. Usually it amounts to a wrapper, written in C++, that exposes C functions and variables, and then in the target language, an OO class framework that encapsulates this wrapper layer. So for every C++ object you end up with some C code that hold the C++ object and provide access to it, and then a whole other proxy object in the target language. Here's a diagram of the bindings for the Qt for Dlang showing the layers and how D has it's own objects, as well as the corresponding C++ objects:
Image
Keeping track of all that is quite complex and it's amazing it all works as well as it does, however I have experienced bugs when the two object models didn't quite hold references in the same way. For example when I was using Python, once I ended up with a Python object that wrapped a Qt C++ object that had already been destroyed due to scoping and reference differences between the two languages. Instant segfault.

This is all simply to show some of the complexities of wrapping C++ in other languages. I've used C++ for many years, and the complexity and skill to create a binding for Qt in another language is well beyond my current abilities. I find it far easier to just use C++ with Qt than it is to try to build a binding for a more user-friendly language. Which is not to say Qt for FB wouldn't be awesome! It sure would and if you succeed, you'll have quite a feather in your cap. C++ is not at all easy to access from any other language.

Another possibility is to not wrap all of Qt, but just enough to support QML. QML is the future of Qt, and it's a much simpler class hierarchy. There are QML bindings for other languages that might serve as a model. QML for FB could be useful for targeting Android.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: I want to do a Qt binding for FB

Post by D.J.Peters »

For x86 and x86_64 FreeBASIC PC target Windows and Linux we have:
Windows9, FLTK-C, IUP, GTK2, GTK3

For FreeBASIC ARM target Raspberry Pi, Beagle bone black etc. we have:
FLTK-C, IUP, GTK2, GTK3

Maybe it would more efficient to write an FLTK-C help file or program simple to use FreeBASIC compatible GUI designers for FLTK-C, Windows 9, IUP etc.

I mean exporting only some widgets from QT is worthless the other GUI libraries are more complete and well tested also.

We germans say "don't work hard work smart" :-)

Joshy
miilvyxg
Posts: 193
Joined: Dec 07, 2021 6:51

Re: I want to do a Qt binding for FB

Post by miilvyxg »

VANYA wrote:For me, QT is not interesting. Freebasic has enough available tools to do whatever you want without the QT library.
Yeah. I understand.
miilvyxg
Posts: 193
Joined: Dec 07, 2021 6:51

Re: I want to do a Qt binding for FB

Post by miilvyxg »

marcov wrote:Another attempt at flattening by the Lazarus people:
original outdated site: http://users.telenet.be/Jan.Van.hijfte/ ... pcqt4.html

current maintainer of qt5 lib: https://github.com/davidbannon/libqt5pa ... tag/v1.2.9
Qt4Pas and Qt5Pas are beast. They are generated by automation tool, after the original developer abandoned it the guy picked it up doing it all manually. I have real respect for him. Anyway, please check the Gambas gb.qt4 and gb.qt5 code and you will realize how limited and small the code base is compared to Qt4Pas and Qt5Pas.
miilvyxg
Posts: 193
Joined: Dec 07, 2021 6:51

Re: I want to do a Qt binding for FB

Post by miilvyxg »

caseih wrote:Yes it would be possible to create bindings for Qt using some of the same tools that are used to create bindings for other languages. There a few automated tools such as SWIG. Such tools are used to create the Qt sharp bindings, python bindings, etc. However the process is very complex. Better than doing it all by hand, which was way we used to do it. Usually it amounts to a wrapper, written in C++, that exposes C functions and variables, and then in the target language, an OO class framework that encapsulates this wrapper layer. So for every C++ object you end up with some C code that hold the C++ object and provide access to it, and then a whole other proxy object in the target language. Here's a diagram of the bindings for the Qt for Dlang showing the layers and how D has it's own objects, as well as the corresponding C++ objects:
Image
Keeping track of all that is quite complex and it's amazing it all works as well as it does, however I have experienced bugs when the two object models didn't quite hold references in the same way. For example when I was using Python, once I ended up with a Python object that wrapped a Qt C++ object that had already been destroyed due to scoping and reference differences between the two languages. Instant segfault.

This is all simply to show some of the complexities of wrapping C++ in other languages. I've used C++ for many years, and the complexity and skill to create a binding for Qt in another language is well beyond my current abilities. I find it far easier to just use C++ with Qt than it is to try to build a binding for a more user-friendly language. Which is not to say Qt for FB wouldn't be awesome! It sure would and if you succeed, you'll have quite a feather in your cap. C++ is not at all easy to access from any other language.

Another possibility is to not wrap all of Qt, but just enough to support QML. QML is the future of Qt, and it's a much simpler class hierarchy. There are QML bindings for other languages that might serve as a model. QML for FB could be useful for targeting Android.
Swig is unable to wrap Qt. Because of the MOC, wrapping of Qt is really difficult. What you described here I already know. Please check the Gambas code of gb.qt4 and gb.qt5 I posted above. It's basically the same idea but they implemented it the very simple yet elegant way. We could learn from them a lot.

QML is nice but do you really want to code in it? It's basically HTML5 and JavaScript. The old QtWidget API is more in line with FB IMO.
Last edited by miilvyxg on Dec 08, 2021 22:03, edited 3 times in total.
miilvyxg
Posts: 193
Joined: Dec 07, 2021 6:51

Re: I want to do a Qt binding for FB

Post by miilvyxg »

D.J.Peters wrote:For x86 and x86_64 FreeBASIC PC target Windows and Linux we have:
Windows9, FLTK-C, IUP, GTK2, GTK3

For FreeBASIC ARM target Raspberry Pi, Beagle bone black etc. we have:
FLTK-C, IUP, GTK2, GTK3

Maybe it would more efficient to write an FLTK-C help file or program simple to use FreeBASIC compatible GUI designers for FLTK-C, Windows 9, IUP etc.

I mean exporting only some widgets from QT is worthless the other GUI libraries are more complete and well tested also.

We germans say "don't work hard work smart" :-)

Joshy
Maybe if you could provide an OOP wrapper of your FLTK-C then I might consider a Qt binding is unnecessary. Your FLTK-C is awesome but it's all procedural code. For people come from an OOP language like me (C++) it's really inconvenient to use. This is also the reason why I wanted to do an OOP wrapper for IUP, IM and CD.
marcov
Posts: 3455
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: I want to do a Qt binding for FB

Post by marcov »

miilvyxg wrote:
marcov wrote:Another attempt at flattening by the Lazarus people:
original outdated site: http://users.telenet.be/Jan.Van.hijfte/ ... pcqt4.html

current maintainer of qt5 lib: https://github.com/davidbannon/libqt5pa ... tag/v1.2.9
Qt4Pas and Qt5Pas are beast. They are generated by automation tool, after the original developer abandoned it the guy picked it up doing it all manually. I have real respect for him. Anyway, please check the Gambas gb.qt4 and gb.qt5 code and you will realize how limited and small the code base is compared to Qt4Pas and Qt5Pas.
FPC/Lazarus is simply massive. Note that in the not so distant past these were also used on OS X, both Carbon and Cocoa were slow to emerge. (In the case of Cocoa because significant language extensions to interface to Objective C were needed).

Nowadays I mostly just use win32. If I look at the FLTK screenshots, I get nineties flashbacks. They somehow missed 30 years of UI design :-)
miilvyxg
Posts: 193
Joined: Dec 07, 2021 6:51

Re: I want to do a Qt binding for FB

Post by miilvyxg »

marcov wrote:FPC/Lazarus is simply massive. Note that in the not so distant past these were also used on OS X, both Carbon and Cocoa were slow to emerge. (In the case of Cocoa because significant language extensions to interface to Objective C were needed).
Oh, another reason for a Qt binding. We can use Qt as the backend for our GUI library on macOS since Qt is natively mapped to Cocoa. There is no need to have a X server installed to be able to use GTK as the backend! Sadly enough, FB doesn't have any builds for macOS nor officially support macOS so this really not make a point :(
Post Reply