本文介绍在不同平台上Eclipse开发环境,本篇是在Windows中进行安装的,请看内容
接着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
- exportJAVA_HOMEJAVA_BINPATHCLASSPATH
2, 安装Eclipse
解压eclipse-cpp-ganymede-SR1-Linux-gtk.tar.gz到/data/opt/下
3, 编译安装qt
- $tarjxvfqt-x11-opensource-src-4.4.3.tar.bz2
- $cdqt-x11-opensource-src-4.4.3
- $./configure-prefix/data/opt/qt-4.4.3-no-libtiff
- $make&&makeinstall
- $vi/data/opt/qt-4.4.3/setqt4(以后在需要编译QT程序时,执行sourcesetqt4就可以设置好环境变量)
- exportQTDIR=/data/opt/qt-4.4.3
- exportPATH=$QTDIR/bin:$PATH
- exportLD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH
4, 让eclipse集成QT
- $cd/data/opt/eclipse
- $tarzxvfqt-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
- intmain(intargc,char*argv[])
- {
- QApplicationapp(argc,argv);
- QPushButtonhello("Helloworld!");
- hello.resize(100,30);
- hello.show();
- returnapp.exec();
- }
测试代码二:
- /*
- *myclass.h
- *
- *Createdon:2008-10-14
- *Author:lj
- */
- #ifndefMYCLASS_H_
- #defineMYCLASS_H_
- #include
- #include
- classMyClass:publicQObject
- {
- public:
- MyClass(constQString&text,QObject*parent=0);
- constQString&text();
- voidsetText(constQString&text);
- intgetLengthOfText();
- private:
- QStringm_text;
- };
- #endif/*MYCLASS_H_*/
- /*
- *myclass.cpp
- *
- *Createdon:2008-10-14
- *Author:lj
- */
- #include"myclass.h"
- MyClass::MyClass(constQString&text,QObject*parent):QObject(parent)
- {
- m_text=text;
- }
- constQString&MyClass::text(){returnm_text;}
- voidMyClass::setText(constQString&text){m_text=text;}
- intMyClass::getLengthOfText(){returnm_text.size();}
- /*
- *main.cpp
- *
- *Createdon:2008-10-14
- *Author:lj
- */
- #include"myclass.h"
- #include
- intmain(intargc,char**argv)
- {
- QObjectparent;
- MyClass*a,*b,*c;
- a=newMyClass("foo",&parent);
- b=newMyClass("ba-a-ar",&parent);
- c=newMyClass("baz",&parent);
- qDebug()<<a->text()<<"("<<a->getLengthOfText()<<")";
- a->setText(b->text());
- qDebug()<<a->text()<<"("<<a->getLengthOfText()<<")";
- returna->getLengthOfText()-c->getLengthOfText();
- }
至此,在windows平台上编译运行QT4程序的设置已经完成,后面就是实际的编程了.
小结:Qt Eclipse开发环境的部署 中篇的内容讲解完了,希望对你有帮助,那么请看 Qt Eclipse开发环境的部署 下篇。
知优网 » Qt Eclipse开发环境的部署 中篇(eclipse qt5环境)