Qt Eclipse開發環境的部署 中篇
接著Qt Eclipse開發環境的部署 上篇開始繼續介紹,配置Linux環境,windows平臺,Eclipse中編寫QT程序。
Linux平臺安裝 (Eclipse ,c++, qt4, fortran)
1, 安裝JDK1.6.bin,并配置環境變量.
安裝目錄/data/opt/jdk1.6.0_01
修改/etc/profile, 在***添加java的環境變量:
- JAVA_HOME=/data/opt/jdk1.6.0_01
- JAVA_BIN=/data/opt/jdk1.6.0_01/bin
- PATH=$PATH:$JAVA_HOME/bin
- CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
- export JAVA_HOME JAVA_BIN PATH CLASSPATH
2, 安裝eclipse
解壓eclipse-cpp-ganymede-SR1-linux-gtk.tar.gz到/data/opt/下
3, 編譯安裝qt
- $tar jxvf qt-x11-opensource-src-4.4.3.tar.bz2
- $cd qt-x11-opensource-src-4.4.3
- $./configure -prefix /data/opt/qt-4.4.3 -no-libtiff
- $make && make install
- $vi /data/opt/qt-4.4.3/setqt4 (以后在需要編譯QT程序時,執行source setqt4就可以設置好環境變量)
- export QTDIR=/data/opt/qt-4.4.3
- export PATH=$QTDIR/bin:$PATH
- export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
4, 讓eclipse集成QT
- $cd /data/opt/eclipse
- $tar zxvf qt-eclipse-integration-linux.x86-gcc3.3-1.4.0.tar.gz
5, 讓eclipse集成fortran支持,方法與windows下相同, 使用的文件也相同
6, 安裝apache2,mysql5,php5,svn服務器
7, 安裝slickedit, matlab7
windows平臺,eclipse中編寫QT程序
一:在eclipse中編寫一般c++程序
1, file->new ->other ->展開C++下的C++ Project ->不選中"Show project types and toolchains only if they are ssupported on the
platform" ->Project Type="Executable"下的"Empty Project", ToolChains="MinGW GCC"
2, 編寫文件或導入現有文件(File -> import ->General 下的 File system)
3, projects -> properties, 展開c/c++ Build,settings,在右側tab頁中選中"Binary Parsers", 應該有兩項是選中的"PE Windows Parser"與"cygwin PE Parser" (默認生成的未選中"cygwin PE Parser"項,造成在下一步生成運行配置時無法自動找到exe)
4, 生成運行配置. "run" -> "run configurations..." , 雙擊"C++ local application"在下面生成一個新的配置"new_configuration", 在右側點"project"后的"browse..."選擇剛才新建的項目名, 點"c/c++ application"后"search project..." 找到可執行文件, 然后就可以點擊"run"運行了.
二:導入有pro文件的qt項目到eclipse中
file -> import -> 選擇qt下qt project ->選擇一個QT的項目文件(xx.pro),就生成一個與原project同名的eclipse項目.但"生成運行配置"還是要做的,之后就可以編譯與運行了.
三,一般C++ Project如何增加對QT的支持
file, new, c++ project => Project type選擇"Executable"下的"Empty Project",不選中"Show project types and toolchains only if they are ssupported on the platform",然后在右側的"Tool Chains"選擇"MinGW GCC",然后點擊"next", 在彈出的對話框中點擊"Advanced settings",展開"c/c++ build" -> "settings",在右側展開"gcc c++ compiler","Directories", 右側"include pathes" , 瀏覽添加d:\Qt\4.4.3\include;
展開"GCC C++ Linker","Libraries",在Libraries(-l)中添加三次,分別添加QtCored4, QtGuid4, qtmaind;
在"Library search path"添加d:\qt\4.4.3\lib;
新建Source File, 輸入代碼,就可以正常編譯了.
測試代碼:
- #include
- #include
- int main(int argc, char *argv[])
- {
- QApplication app(argc, argv);
- QPushButton hello("Hello world!");
- hello.resize(100, 30);
- hello.show();
- return app.exec();
- }
測試代碼二:
- /*
- * myclass.h
- *
- * Created on: 2008-10-14
- * Author: lj
- */
- #ifndef MYCLASS_H_
- #define MYCLASS_H_
- #include
- #include
- class MyClass : public QObject
- {
- public:
- MyClass( const QString& text, QObject *parent = 0 );
- const QString& text() ;
- void setText( const QString& text );
- int getLengthOfText() ;
- private:
- QString m_text;
- };
- #endif /* MYCLASS_H_ */
- /*
- * myclass.cpp
- *
- * Created on: 2008-10-14
- * Author: lj
- */
- #include "myclass.h"
- MyClass::MyClass( const QString &text, QObject *parent ) : QObject( parent )
- {
- m_text = text;
- }
- const QString &MyClass::text() { return m_text; }
- void MyClass::setText( const QString &text ) { m_text = text; }
- int MyClass::getLengthOfText() { return m_text.size(); }
- /*
- * main.cpp
- *
- * Created on: 2008-10-14
- * Author: lj
- */
- #include "myclass.h"
- #include
- int main( int argc, char **argv )
- {
- QObject parent;
- MyClass *a, *b, *c;
- a = new MyClass( "foo", &parent );
- b = new MyClass( "ba-a-ar", &parent );
- c = new MyClass( "baz", &parent );
- qDebug() << a->text() << " (" << a->getLengthOfText() << ")";
- a->setText( b->text() );
- qDebug() << a->text() << " (" << a->getLengthOfText() << ")";
- return a->getLengthOfText() - c->getLengthOfText();
- }
至此,在windows平臺上編譯運行QT4程序的設置已經完成,后面就是實際的編程了.
小結:Qt Eclipse開發環境的部署 中篇的內容講解完了,希望對你有幫助,那么請看 Qt Eclipse開發環境的部署 下篇。