ECLIPSE+QT development environment settings (Linux and Win)

Source: Internet
Author: User
Tags qt designer

Article Summary:
    • Windows,linux platform installation using the Eclipse + QT4.4.3 development environment
    • Windows,linux Configuration when new project is created (not using the QT preset project type, but manually configured)
Reasons to use the Eclipse development platform:For Development on Windows/linux, we want to unify the development tools. when developing QT3, the interface was developed using the designer of QT, and the program can be completed in designer. Sometimes it also uses some lightweight editing tools, such as Windows Flexedit (www.xuyibo.orgdownload, quite good, especially the automatic analysis of C + + source files in the class, method, fast navigation function is very convenient, Linux under the VI (no matter when, vi can not be forgotten, especially when traveling, Linux/unix under the only can be guaranteed to have it). later, using SlickEdit development tools, it is quite convenient to analyze code and write code. It's really handy to work with QT Designer. With the advent of QT4, Qt Designer's functionality is greatly reduced and new integrated development tools are needed. Under Windows, vs2005+visual Assist X + qt is also quite handy, just can't cross the platform. So while learning QT4, try the Eclipse Integration development tool. Windows Platform Installation (Eclipse, C + +, QT4, Fortran)
    • Required Documents:

Dev-cpp4.9.9.2.exe--To use its Integrated MINGW development environment (make and g++)
Qt-win-opensource-4.4.3-mingw.exe---QT Open source version
Eclipse-cpp-ganymede-sr1-win32.zip--integrated with the CDT plugin eclipse
Qt-eclipse-integration-win32-1.4.0.exe---integrate QT into eclipse.

    • installation process

Dev-cpp4.9.9.2.exe installing to the C:\Qt\dev-cpp directory
Qt-win-opensource-4.4.3-mingw.exe Install to C:\Qt\4.4.3 directory (the installation process needs to specify the location of the MinGW, change the default C:\MinGW to C:\Qt\dev-cpp)
Eclipse-cpp-ganymede-sr1-win32.zip directly decompression to C:\Eclipse (need to install JRE environment to run, I use 1.6)
Qt-eclipse-integration-win32-1.4.0.exe you need to specify the location of Eclipse and MinGW during installation, modify the actual installation directory as above. Install to C:\Qt\Trolltech\Eclipse

    • Edit Run QT4 Program

The command line compiles and runs the QT program in three ways:

Law one: the need for "start", "program", "Qt by Nokia v4.4.3 (opensource)", "QT 4.4.3 command Prompt" Open the DOS command Line window, and then compile and run;
Law II: Open any DOS window, execute the C:\qt\4.4.3\bin/qtvars.bat, set the corresponding environment variables.
Law III: Modify the system environment variables:
New environment variable Qtdir with a value of C:\Qt\4.4.3
New environment variable Qmakespec with a value of win32-g++
Modifies the original path variable to increase C:\Qt\4.4.3\bin at the front of the original value; C:\qt\dev-cpp\bin;%systemroot%\system32;
The source code editing tool can use Dev-c++, EditPlus, Flexedit, etc.

Edit, compile, run with Eclipse

Note here that the install Qt-eclipse-integration-win32-1.4.0.exe automatically generated Start menu item "Qt Eclipse integration v1.4.0", "Start eclipse with MinGW "There is a problem. Need to edit the C:\Qt\Trolltech\Eclipse\start.bat, the Qt needs to add the environment variable settings statement, complete the following:

echo Setting up a mingw/qt environment... 
Echo--Qtdir set to C:\Qt\4.4.3
Echo--PATH set to C:\Qt\4.4.3\bin
Echo--Adding C:\Qt\DE V-cpp\bin to Path
Echo--Adding%systemroot%\system32 to Path
Echo--Qmakespec set to win32-g++
set QTDIR=C:\QT \4.4.3 
Set Path=c:\qt\4.4.3\bin
Set path=%path%; C:\Qt\DEV-CPP\bin
Set Path=%path%;%systemroot%\system32
Set qmakespec=win32-g++
Echo starting eclipse ... &NBSP
Call "C:\Eclipse\eclipse.exe"-clean

After launching Eclipse, "File", "new" and "Other", select a project under QT, such as "QT Console project" or "QT GUI project", and then specify the project name, you can use the menu "Projec T, "Build All" is compiled. The debug format is generated by default.
Run, you need to build a run configuration. "Run", "Run configurations ...", double-click "C + + local application" below to generate a new configuration "New_configuration" on the right-hand side "project" after "Browse. ." Select the project name that you just created, click "Search Project ..." after "C + + Application" Locate the executable file and then click "Run" to run it. (Note that if you created QT console project above, you need to create a project, click on "Project", "Properties", double-click "C + + + Make project" on the left, and on the right, select "Binary PA Rser "tab, select" Elf Parse "and" PE Windows Parser ". Otherwise, in "Search Project ..." The executable file will not be found. )

    • Let Eclipse support Fortran:

Download Photran40b4-master.zip
Launch Eclipse, Menu "Help", "Software Updates", check "Available Software" tab, "Add Site ..." In the popup dialog box "Archive ..." to find the phot on the hard drive Ran40b4-master.zip, follow the prompts to complete the installation, restart Eclipse, found in file,new when more support for FORTRAN.

Linux Platform Installation (Eclipse, C + +, QT4, Fortran)
    • Install Jdk1.6.bin, and configure environment variables.

installation directory/data/opt/jdk1.6.0_01
To modify the/etc/profile, add the Java environment variables at the end:

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

    • Install Eclipse
unzip eclipse-cpp-ganymede-sr1-linux-gtk.tar.gz to/data/opt/
    • Compiling and installing 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 (You can set environment variables later when you need to compile the QT program, and then execute the source setqt4.)
Export qtdir=/data/opt/qt-4.4.3
Export path= $QTDIR/bin: $PATH
Export ld_library_path= $QTDIR/lib: $LD _library_path

    • Let Eclipse integrate QT
$CD/data/opt/eclipse
$tar zxvf qt-eclipse-integration-linux.x86-gcc3.3-1.4.0.tar.gz
    • Allow Eclipse to integrate FORTRAN support in the same way as windows, using the same files

    • ­ Installing the APACHE2,MYSQL5,PHP5,SVN server

    • Install SlickEdit, Matlab7
Windows platform, programming QT program in Eclipse
  • Write a generic C + + program in Eclipse
      • File->new->other, C + + project under C + + does not select Show project types and toolchains only if they is ssupported on "Empty Project" under the platform "->project type=" executable ", toolchains=" MinGW GCC "
      • Write a file or import an existing file (file system under File, import->general)
      • Projects Properties, expand C/S + + build,settings, in the Right tab, select "Binary parsers", there should be two items are selected "PE Windows Parser" and "Cygwin PE Parser"(the default generated unchecked" Cygwin PE Parser "entry, which causes the EXE to not be found automatically when the run configuration is generated in the next step)
      • Build the Run configuration. "Run", "Run configurations ...", double-click "C + + local application" below to generate a new configuration "New_configuration" on the right-hand side "project" after "Browse. ." Select the project name that you just created, click "Search Project ..." after "C + + Application" Locate the executable file and then click "Run" to run it.

    • Import QT projects with pro files into eclipse
Select a qt project file (xx.pro), choose QT under QT Project, file--import, and generate an Eclipse project with the same name as the original project. However, "Build run Configuration" is still to be done, then it can be compiled and run.
    • ­ how general C + + project adds support for QT
file, new, C + + project and project type select "Empty project" under "Executable", uncheck "Show Project types and toolchains only if They is ssupported on the platform "and then on the right" Tool Chains "select" MinGW GCC ", then click" Next ", click" Advanced Settings "in the popup dialog, expand" c/c+ + Build "Settings", expand "gcc C + + compiler"on the right, "directories", right "include pathes", browse to add C:\Qt\4.4.3\ Include; expand "GCC C + + Linker", "Libraries", add three times in Libraries (-L), add QtCored4, QtGuid4, qtmaind respectively; add C:\Qt\4.4.3\lib to "Library search path"; Create a new source File and enter the code to compile it properly. Test code:
#include <QtGui/QApplication>
#include <QtGui/QPushButton> int main (int argc, char *argv[])
{
Qapplication app (argc, argv); Qpushbutton Hello ("Hello world!");
Hello.resize (+); hello.show ();
return App.exec ();
}
Test code two:
//Myclass.h
#ifndef Myclass_h_
#define Myclass_h_
#include <QtCore/QString>
#include <QtCore/QObject> 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
#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 #include "myclass.h"
#include <QtCore/QtDebug> 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 ();
}

At this point, the setup to run the QT4 program on the Windows platform is complete, followed by the actual programming.

Linux platform, Eclipse development QT4 Program

    • $source/DATA/OPT/QT-4.4.3/SETQT4 Setting Environment variables

Export qtdir=/data/opt/qt-
Export path= $QTDIR/bin: $PATH
Export ld_library_path= $QTDIR/lib: $LD _library_path

    • Then start eclipse

    • New project, type C + + project under "C + + projects" + Project type = "Executable" under "Empty Project", toolchains= "Linux Gcc" + Point next = "Ad vanced Settings "+ C + + build", "Settings", expand "gcc C + + compiler" on the right, "directories", "right" include   Pathes ", browse to add/data/opt/qt/4.4.3/include; + = expand "GCC C + + Linker", "Libraries", add two times in Libraries (-L), add qtcore, Qtgui, respectively ==> Add/data/opt/qt/4.4.3/lib to "Library Search path"

    • Create a new source File and enter the code to compile it properly.  

      • Possible issues:
        • If you do not set the environment variable ld_library_path before entering Eclipse, the project compiles, but the runtime prompts you not to find the dynamic link library of Qt and fails.
        • The general textbook on the written file contains is #include <qtdebug>, but because the inclusion in the above we added only add the inclusion of the level directory, did not add the following subdirectory, so write the code itself according to the library file subdirectory, Add the owning package name, which becomes # include <QTCORE/QTDEBUG>, or you will be prompted to find the header file at compile time.
        • The third step is simply to demonstrate how to support Qt from a general C + + project by adding a configuration, and the actual development process is that when you create a new project, you can choose QT programs (such as QT Console project, Qt Gui Class, Qt GUI project, QT Resource File), or the QT designer form project under QT Designer. This does not require you to add the appropriate include and LIB. More convenient and quick!

http://cool.worm.blog.163.com/blog/static/6433900620094250839527/

ECLIPSE+QT development environment settings (Linux and Win)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.