Posted on 2006-04-11
Last Modified: 2010-04-02
How to connect C++ code with QT3
Question by:tariq6000
    LVL 20

    Accepted Solution

    hi tariq6000,

    i guess you want it for windows, if not please tell us for which os you want that.

    you have to link your project with qt-mt230nc.lib and qtmain.lib. both are in the "qt-installation-dir\lib". so go to your project-settings and add this in the linker-input-area:


    if you have header, which have to be moc'ed, go to the headers-project-settings and add this:

    COMMAND: %qtdir%\bin\moc.exe $(InputDir)$(InputName).h -o $(InputDir)moc_$(InputName).cpp
    DESCRIPTION: Moc'ing $(InputName).h ...
    OUTPUT: $(InputDir)moc_$(InputName).cpp

    for this header now a "moc_headername.cpp" - file is generated, this you have to add to your project.

    if you have qt-designer-ui-files, you have to add following lines to its settings:

    COMMAND: %qtdir%\bin\uic.exe $(InputPath) -o $(InputDir)$(InputName).h
    %qtdir%\bin\uic.exe $(InputPath) -i $(InputName).h -o $(InputDir)$(InputName).cpp
    %qtdir%\bin\moc.exe $(InputDir)$(InputName).h -o $(InputDir)moc_$(InputName).cpp
    DESCRIPTION: Uic'ing $(InputName).ui ...
    OUTPUT: $(InputDir)$(InputName).h;$(InputDir)$(InputName).cpp;$(InputDir)moc_$(InputName).cpp

    again here is a "moc_uifilename.cpp" - file generated, which has to be added to your project.

    tell us, if you have problems making this setup.

    good luck :)
    LVL 12

    Assisted Solution

    1. A easy way is to copy the example project from
    And add and remove files as per your requirement.

    2. Make your project file and use qmake to do your job.

    3. As said by ikework.

    If you are new to Qt then I will suggest you to use the first method.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
    IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now