How to run a C++ code in Qt?

  • Lifetime Qt Champion

    That's what I mean. Avoid white spaces it's the best thing to do on Windows.

  • @SGaist
    Just to be sure which one I need to install?Qt5.6

  • Lifetime Qt Champion

    The second one unless you are planning to use WinRT

  • @SGaist
    I dont have any idea about that, I was just running a C++ code in Qt and get outputs in UI... how can I know if it was installed before in Qt5.5? Moreover, there is a "_64" difference between the two: qt-opensource-windows-x86-msvc2015_64-5.6.0-beta.exe 17-Dec-2015 and

  • Lifetime Qt Champion

    The _64 is to be used if you want to build a 64 bit version of your application. That also requires a 64 bit OS to run.

    The Beta doesn't installed itself in 5.5 since it's the 5.6 beta

  • @SGaist
    My system is windows 7 64-bit, and I am going to run a C++ code using Qt with MCVS 2015.
    Just to prevent from over or re-installation again, could you please tell me which one I need to install?

  • Lifetime Qt Champion

    If you plan to only run your application on 64bit Windows, then take the 64bit version otherwise the 32.

  • @SGaist
    I installed the first one here to be able to run my projects using MCVS 2015 compiler. It worked last week. I think I have still the older Qt 5.5. and couldn't uninstall it.
    Now I am again trying to run my project, but cannot find the Qt5.6 beta. when I open the Qt shortcut on my desktop, it has only the MCVS 2013 as compiler.
    How can I run projects using Qt 5.6 beta shown here and get rid of Qt 5.5?
    In addition, when I open the "MaintenanceTool.exe" to update it, this error appears.

  • Lifetime Qt Champion

    Qt 5 beta should be installed somewhere like C:\Qt\5.6.0. In any case you are probably using the Qt 5.5 installed Qt Creator. Either add a Qt Version and a Kit in the Preferences of Qt Creator using your Qt 5.6 beta or start the Qt Creator from Qt 5.6 beta.

    If you don't what that mix, just remove both and re-install only Qt 5.6 beta.

    There's nothing to update in a beta version.

  • @SGaist said:

    Yes, Qt 5.6 beta is in C:\Qt\5.6.0. This is my Qt5.6 beta that I sent in previous post. But may I ask how to start the Qt Creator from Qt 5.6 beta?
    Could you please let me know how to "add a Qt Version and a Kit in the Preferences of Qt Creator using Qt 5.6 beta "?

    I was going to uninstall Qt 5.5. before installing Qt 5.6. beta, but it gave this error asked in one of my previous posts.

  • Lifetime Qt Champion

    Like written on the dialog, don't install Qt in "Program Files", the spaces always poses problems.

    Then use the Qt Creator from Qt 5.6 so you don't have to configure anything special, it should already have it auto-detected.

  • @SGaist said:

    The Qt 5.6 beta was installed in C:\Qt\5.6.0, not program file.
    Qt 5.5 was previously installed in program files, but it worked properly. When I open Qt 5.6., this folders appear, I dont know where the Qt Creator from Qt 5.6 is.
    When I open the Qt creator on desktop, it only shows this compiler, not "Desktop Qt 6.5. MSVC 2015".
    I am wondering last week, I could run it immediately after I installed Qt5.6. beta.

  • Qt Champions 2019

    QtCreator should be in C:\Qt\5.6.0\Tools
    You can create a Kit with the right compiler and Qt version in QtCreator under Tools/Options/Build & Run

  • @jsulm
    Thanks, could you tell me the exact path of 5.6 beta creator in tools here?

  • Qt Champions 2019

    If it is there you should find it.
    But here is the path: C:\Qt\5.6.0\Tools\QtCreator\bin\qtcreator.exe

  • @jsulm

    Thanks, It works now, but how can I replace it on desktop with previous Qt5.5 creator?

  • Qt Champions 2019

    You mean you want to have a short-cut on the desktop? Drag and drop qtcreator.exe to the desktop using right mouse button and then select "Create shortcuts here"

  • @jsulm
    Thanks, I thought I first need to uninstall the previous version.

  • This post is deleted!

  • Previously I tried a simple project to print out "Hello world" in one of my previous posts. The C++ code was written in MSVC 2013 gives output. Here is one of my previous posts related to getting output of C++ code written in MCVS 2013 in Qt5.5.
    Here is my previous post:
    "The above output was the debug using "Desktop Qt 5.5.1 MSVC2013 64 bit". I didnt debug with MinGW. The problem is the way I use to get the results in UI.
    I tried a simple project to print out "Hello world", the C++ code written in MSVC gives output. Could you please take a look at my files:
    Here are the content of C++ all files.
    Now I created a Qt widget project, and I added the C++ code stdafx.h, targetver.h, and stdfx.cpp files using "Add existing Files" to the header and source. I didnt add Bucky9.cpp and main.cpp. Instead, I coppied the main.cpp C++ codes in the Qt main.cpp file with a little changes of all files.
    (Changes: 1- Bucky9 is not included in Qt.
    2- In stdafx.h #include <char.h> instead of <tchar.h>
    3- Including #include "stdafx.h" in mainwindow.cpp.

    Here are the content of all files in Qt project:

    I could get "Hello worlds" with QLabel using Qt5.5 and MCVS 2013. The only difference is that I didnt change <tchar.h> in stdafx.h. Now, when I run it, it builds it, but the run button is not active. Here is the code: Qt code
    Is there any change when I am working with MCVS 2015 and Qt 5.6 beta? Some of my Qt 5.5. works, but some of them dont work.

  • Qt Champions 2019

    What is the content of your *.pro file?

  • Thanks it worked today, the run button was active and gave "Hello world" in widget.
    Just I am doing the same with another longer C++ code. I copied all .h and .cpp files to the created Qt project folder and added using
    "Add existing file" to Qt .h and .cpp files. But instead of main.cpp in Qt, I copied the .cpp code in my PS C++ project. When I run it it gives more than 10 errors like

    "\\\ab\data\Documents\Qt projects\PS7\main.cpp:1060: error: C2664: 'void PSError(char *)': cannot convert argument 1 from 'const char [37]' to 'char *'' in main.cpp file.

    I changed the the #include <tchar.h> to #include <char.h> in "stdafx.h" file, but the error decreased to two including ```

    "\\\ab\data\Documents\Qt projects\PS7\stdafx.h:11: error: C1083: Cannot open include file: 'char.h': No such file or directory"
    PS. May I ask why I cannot see my previous posts in this page? I need sometimes to look at them, how can I do that?

  • Lifetime Qt Champion

    Just to be clear, are you trying to build MSVC generate code with a MinGW build of Qt ?
    If so why not just import the code you wrote in your VS project in your Qt project and dump the VS specific files that you anyway will not use in your Qt project ?

    If you have the infinite scroll activated, just scroll up otherwise you have a at the bottom a page selector.

  • @SGaist
    I think I wrote by mistake. I am trying to run my C++ project using Qt Widget project.
    I have these files VS I copied them in my Qt project folder, and added stdafx.cpp, stdafx.h, targetver.h and O_PS .H to the Qt. Instead of adding "O_PS .cpp" I copied its content to the "main.cpp" in Qt. For "po .cpp" also I just added
    #include "stdafx.h" to the "mainwindow.cpp". Now I have these files in Qt: Qt

    The errors were explained in the previous post.

  • Qt Champions 2019

    See here:
    stdafx.h seems to be generated by VS, so you should not use it with MinGW

  • @jsulm
    If I understood your post, I dont run the Qt with MinGW, here I run it using Desktop MCVS 2015 compiler, after adding the path of the input data file to the Run of the MCVS 2015 in the project.

  • Could you please tell your ideas about my previous question posted 6 days ago?

  • Qt Champions 2019

    Please take a look at error messages you get:

    "\\\ab\data\Documents\Qt projects\PS7\main.cpp:1060: error: C2664: 'void PSError(char *)': cannot convert argument 1 from 'const char [37]' to 'char *'' in main.cpp file.

    Now check the code lines mentioned in these error messages. Error message you posted tells you that you are passing a const char array to a function that takes a non-const char*. This is not allowed.

  • But previously it did not give that error, when I did the same with different versions of Qt5.5 and MCVS 2013. The number of errors

     cannot convert argument 1 from 'const char [37]' to 'char *''

    is about 12-13.
    However, when I change the

    #include <tchar.h>


    #inclu```de <char.h>

    in "stdafx.h" file, the error decreased to two including

    \\\ab\data\Documents\Qt projects\PS7\stdafx.h:11: error: C1083: Cannot open include file: 'char.h': No such file or directory


  • Could you please reply me?

  • @Rela

    I don't remember that there is any char.h file.

  • @the_
    Thanks, could you please read my last 6 previous posts?

  • I did the same process to read the C++ project in Qt Creator, but this time the error is ```

    :-1: error: dependent '..\C++' does not exist.

    These are my C++ project files:

    and I built a mainwindow Qt creator project (PS8) and copied all the files in the Qt folder except "ps.cpp" and "O_PS.CPP". The copied ones were added to the Qt project using "Add Existing Files". There are some differences including:
    1- The "ps.cpp" contains only ```

    #include "stdafx.h"

    which was added to "mainwindow.cpp".
    2- "O_PS.CPP" content was copied in the "main.cpp" of the Qt project. The Qt PS8 project now includes these files.

  • Lifetime Qt Champion

    I'm going to repeat myself but: why not just start from a clean Qt project, copy the code you need to run over in that project and go on ?

    You have some core logic in that visual studio project but rather than just take the current working code and move it over to your Qt project with maybe some adaptations, you are trying to grab every bits of that project and mix it with your Qt project when there's no real need.

  • @SGaist
    I almost did the same, except I added the files "stdafx.h", "targetver.h", "stdafx.cpp", and "O_PS .H", which I think are needed. Because in this C++ code, only the "O_PSA .H" and "O_PS .CPP" include code.
    The content of "stdafx.h" is #include```

    #include <stdio.h>
    #include <tchar.h>

    The content of "targetver.h" is ```

    #include <SDKDDKVer.h>

    The content of "stdafx.cpp" is ```

    #include "stdafx.h"

    And the content of "po .cpp" is ```

    #include "stdafx.h"

    But, if you mean I just copy the "O_PSA .H" and "O_PS .CPP" codes in "mainwindow.h" and "main.cpp", (here is the Qt project it gives many errors, and I think because all cpp and header files are necessary.

  • Lifetime Qt Champion

    You have to fix the includes in your O_PS* files so add the missing #include <stdio.h>

  • @SGaist
    Do I add #include <stdio.h> to "mainwindow.h" ? I added to all files one by one , but the same errors happen.
    Do I need to add #include "stdafx.h" or something else also?

  • Lifetime Qt Champion

    No, include them in your O_PS* files where suited.

  • @SGaist
    I copied the "O_PSA .H" and "O_PS .CPP" code in the "mainwindow.h" and "main.cpp" of the Qt project respevtively. I did add ```

    #include <stdio.h> 

    in either "mainwindow.h" or "main.cpp" files, but it gave the same errors

  • Qt Champions 2017

    It must have taken you ages to delete those names ... Anyway, to use ostream, istream and other streams from the standard C++ library, you actually need to include the corresponding headers - stdio.h simply won't cut it. You need (depending on which classes you use) one of the *stream headers, e.g. #include <iostream>, #include <fstream> and so on. Additionally, these classes come in the std namespace so you'd need to expand that as well, for example.

    #include <iostream>
    using namespace std;
    // Only now the istream and ostream classes are available.

    Kind regards.

Log in to reply