PDA

View Full Version : Qt fails on tutorial



Goslowjimbo
23rd November 2006, 05:11 PM
I have Fedora 6 and Qt3, both installed just this week on a Pentium desktop, with a dual boot to Windows XP PRO. In trying to learn Qt3, I started the tutorials in Blanchette's and Summerfield's book. When I try to make the 2nd tutorial, ("QUIT"), I get roughly 2000 errors, almost all related to libraries. I know enough about programming to comment out lines to find the offending code. I wound up commenting out the whole program and having the same problem. I found 2 variations of the QUIT program on the net and tried both of them with the same results. I have even tried copying the first tutorial (which worked in it's own directory) into the QUIT.c file, commenting out the whole QUIT program, and re-making. I erase all but the ".c" file in the directory, and use the 2 qmakes, then the make. I still have the same problem. What is going on and what do I do to fix this?

markkuk
24th November 2006, 01:14 AM
Show the code, the commands you used and the errors, otherwise it's impossible to say what the problem is.

Goslowjimbo
24th November 2006, 03:46 AM
OK, it's awful lengthy, but here it is:

The Program:

/************************************************** **************
**
** Qt tutorial 2
**
************************************************** **************/

#include <qapplication.h>
#include <qpushbutton.h>
#include <qfont.h>


int main( int argc, char **argv )
{
QApplication a( argc, argv );

QPushButton quit( "Quit", 0 );
quit.resize( 75, 30 );
quit.setFont( QFont( "Times", 18, QFont::Bold ) );

QObject::connect( &quit, SIGNAL(clicked()), &a, SLOT(quit()) );

a.setMainWidget( &quit );
quit.show();
return a.exec();
}

The program was stored as Leave.c under the /Leave subdirectory.

COMMANDS:

[jsr@localhost ~]$ cd Leave
[jsr@localhost Leave]$ qmake -project
[jsr@localhost Leave]$ qmake
[jsr@localhost Leave]$ make

RESULTS:

gcc -c -pipe -Wall -W -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -DQT_NO_DEBUG -DQT_SHARED -DQT_THREAD_SUPPORT -I/usr/lib/qt-3.3/mkspecs/default -I. -I. -I/usr/lib/qt-3.3/include -o Leave.o Leave.c
In file included from /usr/lib/qt-3.3/include/qwindowdefs.h:43,
from /usr/lib/qt-3.3/include/qwidget.h:42,
from /usr/lib/qt-3.3/include/qdesktopwidget.h:40,
from /usr/lib/qt-3.3/include/qapplication.h:42,
from Leave.c:7:
/usr/lib/qt-3.3/include/qobjectdefs.h:152: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QObject’
/usr/lib/qt-3.3/include/qobjectdefs.h:153: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QMetaObject’
/usr/lib/qt-3.3/include/qobjectdefs.h:154: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QSignal’
/usr/lib/qt-3.3/include/qobjectdefs.h:155: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QConnection’
/usr/lib/qt-3.3/include/qobjectdefs.h:156: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QEvent’
/usr/lib/qt-3.3/include/qobjectdefs.h:158: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QConnectionList’
/usr/lib/qt-3.3/include/qobjectdefs.h:159: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QConnectionListIt’
/usr/lib/qt-3.3/include/qobjectdefs.h:160: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QSignalVec’
/usr/lib/qt-3.3/include/qobjectdefs.h:161: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QObjectList’
/usr/lib/qt-3.3/include/qobjectdefs.h:162: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QObjectListIt’
/usr/lib/qt-3.3/include/qobjectdefs.h:163: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QMemberDict’
/usr/lib/qt-3.3/include/qobjectdefs.h:165: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/lib/qt-3.3/include/qobjectdefs.h:169: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
/usr/lib/qt-3.3/include/qobjectdefs.h:171: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token

I hope this enough to show what's happening. The error file was 300 Kb.

markkuk
24th November 2006, 09:23 AM
Qt programs are C++, not C. You must use the .cpp suffix for C++ source files that use Qt, rename your source file to Leave.cpp.

Goslowjimbo
24th November 2006, 02:18 PM
Oh - I'm used to programming VERY small micros with special compilers, so I didn't realize gcc made a distinction between C and C++. Thanks for the input.