Qt with FB

User projects written in or related to FreeBASIC.
Stueber
Posts: 46
Joined: Nov 22, 2009 16:20

Qt with FB

Post by Stueber »

Hi,
I started to write a small wrapper for Qt and FB. I've uploaded a very early version of the wrapper >>>here<<<. It's only a demo that shows what is possible and I will translate more and more classes and functions in the next months.

Here's an example:

Code: Select all

#inclib "QtWrapper"
#include once "QMainWindow.bi"
#include once "QApplication.bi"
#include once "QPushButton.bi"
#include once "QVBoxLayout.bi"


dim as QApplication app

dim as QMainWindow main = QMainWindow()
dim as QWidget widget = QWIdget()
dim as QPushButton button1 = QPushButton("Exit")

dim as QVBoxLayout vbox = QVBoxLayout(@widget)
vbox.addWidget(@button1)

main.setCentralWidget(@widget)
main.show()


QObject.connect(@button1,"clicked(bool)",@app,"quit()")

app.setStyle("Cleanlooks")
app.exec()
The example creates a Button. If you click the Button the application will be closed.
I solved also problems with the virtual functions of QWidget, you can call the original implementation with QWidget.callDefault and "overwite" the function with a callback system (QWidget.setCallback()).
The next step will be the implementation of Signals and Slots in UDTs. (connections from Qt classes to Qt classes work already).

Thank you for any feedback!
rdc
Posts: 1741
Joined: May 27, 2005 17:22
Location: Texas, USA
Contact:

Post by rdc »

Great idea for a project. This could be very useful.
BasicScience
Posts: 489
Joined: Apr 18, 2008 4:09
Location: Los Angeles, CA
Contact:

Post by BasicScience »

Bravo. This will be a terrific addition.

I realize you are just getting started... but when I recompiled Test.Bas the warning appeared. Application ran just fine.

Compiler output:
warning 3(1): Passing different pointer types, at parameter 1 (w) of ADDWIDGET()

System:
FBIde: 0.4.7 unicode
fbc: FreeBASIC Compiler - Version 0.20.0 (08-10-2008) for win32 (target:win32)
OS: Windows XP (build 2600, Service Pack 3)
Stueber
Posts: 46
Joined: Nov 22, 2009 16:20

Post by Stueber »

I wrote a macro for this warning, you can write "vbox.addWidget(Q_WIDGET(@button1))" instead of "vbox.addWidget(@button1)"
cha0s
Site Admin
Posts: 5319
Joined: May 27, 2005 6:42
Location: USA
Contact:

Post by cha0s »

Awesome dude. Really cool getting this started, thank you!
Sisophon2001
Posts: 1706
Joined: May 27, 2005 6:34
Location: Cambodia, Thailand, Lao, Ireland etc.
Contact:

Post by Sisophon2001 »

Of the cross platform libraries I have seen in actual applications, I think Qt looks and behaves the best, so I think this will be very nice if you can manage to get it fully functional.

Garvan
joseywales72
Posts: 206
Joined: Aug 27, 2005 2:02
Location: Istanbul, Turkey

Post by joseywales72 »

It would be great to have QT as a GUI library to use with FB. Thank you for the effort.
Btw, I tried to compile your wrapper on Linux, but it gave these errors and quit.

Code: Select all

g++ -c -pipe -march=i686 -mtune=generic -O2 -pipe -Wall -W -D_REENTRANT -fPIC -DQTWRAPPER_LIBRARY -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. -o qtwrapper.o qtwrapper.cpp
qtwrapper.cpp:19: error: expected constructor, destructor, or type conversion before ‘(’ token
qtwrapper.cpp:25: error: expected constructor, destructor, or type conversion before ‘(’ token
I tried to run Qmake first, than issue a Make command. Also I tried it without giving a Qmake command first but no use. I also tried to change all the linefeed chars to unix counterparts.
I can compile other Qmake based apps on my PC. I'm not a C/C++ programmer so, I may be wholly wrong how to do this.
Also not a native speaker so forgive my potential mistakes too.

Anil
Stueber
Posts: 46
Joined: Nov 22, 2009 16:20

Post by Stueber »

I'm not sure, but maybe g++ doesn't support "__declsprec()". I will compile the wrapper for Linux to a .so file in the next days.
joseywales72
Posts: 206
Joined: Aug 27, 2005 2:02
Location: Istanbul, Turkey

Post by joseywales72 »

Great news... Thanks..
Stueber
Posts: 46
Joined: Nov 22, 2009 16:20

Post by Stueber »

Today, I translated the most important functions of QString and QFile. I'm working on QIODevice and QByteArray right now.
You can get it >>>here<<<

I don't forgot the linux build, but first I have to install a 32bit linux. :)
Stueber
Posts: 46
Joined: Nov 22, 2009 16:20

Qt without Wrapper

Post by Stueber »

Hi,
I managed to use C++ Functions of Qt in FB without any wrapper. I thought FreeBASIC can't use C++ functions. Can anyone explain why this source code is working? *LINK*
The archive includes everything needed to test the source code (DLLs, header, .a files, test programm).

Thank you in advance.
v1ctor
Site Admin
Posts: 3804
Joined: May 27, 2005 8:08
Location: SP / Bra[s]il
Contact:

Post by v1ctor »

You could also do this (UNTESTED):

Code: Select all

'' QApplication.bi
extern "C++"
	type QApplication alias "QApplicationWrapper"
	 public:
	    declare constructor (argc as integer, argv as zstring ptr ptr)
	    declare destructor ()
	    declare sub exec( )
	    
	 private:
	    dim as any prt qa
	end type
end extern
// QApplicationWrapper.cpp

...

class QApplicationWrapper
{
private:
QApplication *qa = null;

public:
QApplicationWrapper( int argc, char *argv[] )
{
qa = new QApplication( argc, argv );
}

~QApplicationWrapper( )
{
delete qa;
}

void exec( )
{
qa.exec( );
}
}
It would make it easier to create the headers than using C in the C++ side, IMO. It is also way more safe than making assumptions on the C++ class sizes (the new byte[n] stuff).
Stueber
Posts: 46
Joined: Nov 22, 2009 16:20

Post by Stueber »

Your right, but how to handle with classes as parameters? I tried your example with integers and it worked but with Qpoint it doesn't work. My example works with classes or templates as parameters.
Stueber
Posts: 46
Joined: Nov 22, 2009 16:20

Signals and Slots

Post by Stueber »

Today, I was able to write a slot in FreeBASIC and connect it with a signal! I connected the slot with the clicked signal of a button and it worked. I clicked the button and the signal was emitted.

Here's the example src (~22kb): *Link*
Here's the example with dll's (~3.3mb): *Link*
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

good idea

Joshy
Post Reply