PDA

View Full Version : I'm a fresh,how this problem could be resolved?



defyer
16th July 2007, 06:41
here's the output in my terminal:
(it's just a very simple hello,world program)


g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o hello.o hello.cpp
hello.cpp: In function ‘int main(int, char**)’:
hello.cpp:8: error: ‘class QApplication’ has no member named ‘setMainWidget’
make: *** [hello.o] Error 1

rajesh
16th July 2007, 06:44
Can you post your code? main()

defyer
16th July 2007, 07:02
oh,sorry, I forget...
here it is, I think it may be caused by the compatibility, for I installed the Qt4 on my machine, but the program is Qt3 version(got from the book <<C++ GUI Programming with Qt3>>):

#include <QApplication>
#include <QLabel>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!", 0);
app.setMainWidget(label);
label->show();
return app.exec();
}

and here the Qt installation on my Ubuntu 7.04 laptop:

defyer@ubuntuyn:~$ dpkg -l |grep qt4
rc libqt4-core 4.2.3-0ubuntu3 Qt 4 core non-GUI functionality runtime libr
ii libqt4-core-kdecopy 4.3.0~beta1-0ubuntu2 Qt 4 core non-GUI functionality runtime libr
ii libqt4-dev-kdecopy 4.3.0~beta1-0ubuntu2 Qt 4 development files
rc libqt4-gui 4.2.3-0ubuntu3 Qt 4 core GUI functionality runtime library
ii libqt4-gui-kdecopy 4.3.0~beta1-0ubuntu2 Qt 4 core GUI functionality runtime library
rc libqt4-qt3support 4.2.3-0ubuntu3 Qt 3 compatibility library for Qt 4
ii libqt4-qt3support-kdecopy 4.3.0~beta1-0ubuntu2 Qt 3 compatibility library for Qt 4
rc libqt4-sql 4.2.3-0ubuntu3 Qt 4 SQL database module
ii libqt4-sql-kdecopy 4.3.0~beta1-0ubuntu2 Qt 4 SQL database module
rc qt4-designer 4.2.3-0ubuntu3 Qt 4 Designer
ii qt4-designer-kdecopy 4.3.0~beta1-0ubuntu2 Qt 4 Designer
ii qt4-dev-tools-kdecopy 4.3.0~beta1-0ubuntu2 Qt 4 development tools
ii qt4-doc-kdecopy 4.3.0~beta1-0ubuntu2 Qt 4 API documentation
ii qt4-qtconfig-kdecopy 4.3.0~beta1-0ubuntu2 Qt 4 configuration tool

thank u!

rajesh
16th July 2007, 07:26
remove //app.setMainWidget(label);

QApplication:: (http://www.qtcentre.org/forum/qapplication-qt3.html#setMainWidget)setMainWidget (http://www.qtcentre.org/forum/qapplication-qt3.html#setMainWidget)() is no longer used in Qt4. When all an application's windows are closed, the application will exit normally.

defyer
16th July 2007, 07:50
yes, it works, thanks:)
so, I'd better to use Qt3 to compile the program from that book?
if I put more than one widgets, what comes? is that necessary to "setMainWidget"?if not , what shoud I do?

rajesh
16th July 2007, 08:03
you create mainWindow object in main or any user define class object in main. then you add widget in mainWindow or your defined class.
you can see example from http://doc.trolltech.com/4.3/examples.html

patrik08
16th July 2007, 08:04
yes, it works, thanks:)
so, I'd better to use Qt3 to compile the program from that book?
if I put more than one widgets, what comes? is that necessary to "setMainWidget"?if not , what shoud I do?

Or choise a qt4 book..

Your existing qt3 code can transform to qt4
http://doc.trolltech.com/4.2/qt3to4.html
qt3to4 myapp.pro

Tip: compile self the package.. to best performance
http://www.qtforum.de/forum/viewtopic.php?t=4044


apt-get source libqt4-core
## get dependency
apt-get build-dep libqt4-core
apt-get install fakeroot
cd qt*
dpkg-buildpackage -us -uc -rfakeroot