1. Hello Qt
问题:
jason@jason-desktop:~/my_doc/qt/test/chap01/hello$ qmake -project
jason@jason-desktop:~/my_doc/qt/test/chap01/hello$ qmake
jason@jason-desktop:~/my_doc/qt/test/chap01/hello$ make
g++ -c -pipe -g -Wall -W -O2 -D_REENTRANT -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED -DQT_TABLET_SUPPORT -I/usr/share/qt3/mkspecs/default -I. -I. -I/usr/include/qt3 -o hello.o hello.cpp
hello.cpp:15:24: error: QApplication: 没有该文件或目录
hello.cpp:16:18: error: QLabel: 没有该文件或目录
hello.cpp: In function ‘int main(int, char**)’:
hello.cpp:20: error: ‘QApplication’ was not declared in this scope
hello.cpp:20: error: expected ‘;’ before ‘app’
hello.cpp:21: error: ‘QLabel’ was not declared in this scope
hello.cpp:21: error: ‘label’ was not declared in this scope
hello.cpp:21: error: expected type-specifier before ‘QLabel’
hello.cpp:21: error: expected ‘;’ before ‘QLabel’
hello.cpp:23: error: ‘app’ was not declared in this scope
hello.cpp: At global scope:
hello.cpp:18: warning: unused parameter ‘argc’
hello.cpp:18: warning: unused parameter ‘argv’
make: *** [hello.o] 错误 1
jason@jason-desktop:~/my_doc/qt/test/chap01/hello$
原因:
QT3与QT4版本之间不兼容问题。QT4的代码用QT3编译
解决:
jason@jason-desktop:~/my_doc/qt/test/chap01/hello$ qmake-qt4 -project
jason@jason-desktop:~/my_doc/qt/test/chap01/hello$ qmake-qt4
jason@jason-desktop:~/my_doc/qt/test/chap01/hello$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o hello.o hello.cpp
g++ -Wl,-O1 -o hello hello.o -L/usr/lib -lQtGui -lQtCore -lpthread
jason@jason-desktop:~/my_doc/qt/test/chap01/hello$
××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
问题:
jason@jason-desktop:~/my_doc/qt/test/chap01/hello$ qmake -project
jason@jason-desktop:~/my_doc/qt/test/chap01/hello$ qmake
jason@jason-desktop:~/my_doc/qt/test/chap01/hello$ make
g++ -c -pipe -g -Wall -W -O2 -D_REENTRANT -DQT_NO_DEBUG -DQT_THREAD_SUPPORT -DQT_SHARED -DQT_TABLET_SUPPORT -I/usr/share/qt3/mkspecs/default -I. -I. -I/usr/include/qt3 -o hello.o hello.cpp
hello.cpp:15:24: error: QApplication: 没有该文件或目录
hello.cpp:16:18: error: QLabel: 没有该文件或目录
hello.cpp: In function ‘int main(int, char**)’:
hello.cpp:20: error: ‘QApplication’ was not declared in this scope
hello.cpp:20: error: expected ‘;’ before ‘app’
hello.cpp:21: error: ‘QLabel’ was not declared in this scope
hello.cpp:21: error: ‘label’ was not declared in this scope
hello.cpp:21: error: expected type-specifier before ‘QLabel’
hello.cpp:21: error: expected ‘;’ before ‘QLabel’
hello.cpp:23: error: ‘app’ was not declared in this scope
hello.cpp: At global scope:
hello.cpp:18: warning: unused parameter ‘argc’
hello.cpp:18: warning: unused parameter ‘argv’
make: *** [hello.o] 错误 1
jason@jason-desktop:~/my_doc/qt/test/chap01/hello$
原因:
QT3与QT4版本之间不兼容问题。QT4的代码用QT3编译
解决:
jason@jason-desktop:~/my_doc/qt/test/chap01/hello$ qmake-qt4 -project
jason@jason-desktop:~/my_doc/qt/test/chap01/hello$ qmake-qt4
jason@jason-desktop:~/my_doc/qt/test/chap01/hello$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o hello.o hello.cpp
g++ -Wl,-O1 -o hello hello.o -L/usr/lib -lQtGui -lQtCore -lpthread
jason@jason-desktop:~/my_doc/qt/test/chap01/hello$
××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××