Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. How to run a C++ code in Qt?

How to run a C++ code in Qt?

Scheduled Pinned Locked Moved Installation and Deployment
123 Posts 5 Posters 108.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J jsulm
    25 Nov 2015, 13:50

    I don't know which of them you have to remove. I don't know your code and I don't know what you want to do. You have to decide which of them is the right one and then just delete the other. You just cannot have more than one entry point (more than one main function) in a C/C++ program.

    R Offline
    R Offline
    Rela
    wrote on 25 Nov 2015, 14:21 last edited by
    #26

    @jsulm
    I definitely need my C++ code, because everything to get the results is in the code, but when I create a new project in Qt, the "main.cpp" file is also created. If I right click on it and "Remove File" do I need add this code somewhere?

    I had Qt5.4.1 before, and it gave results in "Application output" previously using “Desktop Qt5.4 MinGW” with the same main functions.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 25 Nov 2015, 15:36 last edited by
      #27

      If you already have a main function that does everything then no. Just keep this in mind: having your main function in a file not named main.cpp is pretty unusual for an application, not forbidden, just unusual. Beware of maintenance nightmare.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply 1 Dec 2015, 11:29
      0
      • S SGaist
        25 Nov 2015, 15:36

        If you already have a main function that does everything then no. Just keep this in mind: having your main function in a file not named main.cpp is pretty unusual for an application, not forbidden, just unusual. Beware of maintenance nightmare.

        R Offline
        R Offline
        Rela
        wrote on 1 Dec 2015, 11:29 last edited by Rela 12 Jan 2015, 11:34
        #28

        @SGaist

        I created another project file, and added the C++ files, but instead of adding the code .cpp file I copied it in "main.cpp" file. The only change I made was that copied the

        QApplication a(argc, argv);
            MainWindow w;
            w.show();
        

        After
        int main(int argc, char *argv[])
        {
        . So, now there is only one main function in "main.cpp".

        After that I added the text file by "Argument", using MinGW 32bit, gives this "Runtime Library" error: MinGW 32bit I read maybe its because MinGW is 32bit and I need to use 64 bit as compiler.
        And used "Desktop Qt5.5.1 MSVC 2013 64 bit" , it gives this error: MSVC 64bit

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 1 Dec 2015, 11:33 last edited by
          #29

          Run it through the debugger, you're doing something fishy in your code. Throwing a bad alloc means that you are trying to allocated more memory than it's available. It might pass on 64bit (not the same memory limits) but if it does, it means that you are doing something else that is wrong and makes your application crash.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 2 Replies Last reply 1 Dec 2015, 12:03
          0
          • S SGaist
            1 Dec 2015, 11:33

            Run it through the debugger, you're doing something fishy in your code. Throwing a bad alloc means that you are trying to allocated more memory than it's available. It might pass on 64bit (not the same memory limits) but if it does, it means that you are doing something else that is wrong and makes your application crash.

            R Offline
            R Offline
            Rela
            wrote on 1 Dec 2015, 12:03 last edited by
            #30
            This post is deleted!
            1 Reply Last reply
            0
            • S SGaist
              1 Dec 2015, 11:33

              Run it through the debugger, you're doing something fishy in your code. Throwing a bad alloc means that you are trying to allocated more memory than it's available. It might pass on 64bit (not the same memory limits) but if it does, it means that you are doing something else that is wrong and makes your application crash.

              R Offline
              R Offline
              Rela
              wrote on 1 Dec 2015, 12:13 last edited by
              #31

              @SGaist
              When I click on MSVC to debug MSVC and "F5", it gives this error: No engine
              When I use MinGW and "F5", it gives this error: MinGW

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 1 Dec 2015, 12:20 last edited by
                #32

                You need to install the debugger for MSVC

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                R 1 Reply Last reply 1 Dec 2015, 13:00
                0
                • S SGaist
                  1 Dec 2015, 12:20

                  You need to install the debugger for MSVC

                  R Offline
                  R Offline
                  Rela
                  wrote on 1 Dec 2015, 13:00 last edited by
                  #33

                  @SGaist
                  In "Maintenance Tool.exe" these components were chosen. components Do I need to mark "Windows Runtime" also?
                  In "Build & Run", there is one debugger, if it should be added manually, from which folder I have to select it? Debugger

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 1 Dec 2015, 15:35 last edited by
                    #34

                    MSVC debugger can only be obtained from Microsoft website, here

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    R 2 Replies Last reply 2 Dec 2015, 10:34
                    0
                    • S SGaist
                      1 Dec 2015, 15:35

                      MSVC debugger can only be obtained from Microsoft website, here

                      R Offline
                      R Offline
                      Rela
                      wrote on 2 Dec 2015, 10:34 last edited by
                      #35

                      @SGaist
                      Thanks, should I install SDK or WDK?
                      I did search,but it is said that CDB goes with Visual C++, but there is not download link for CDB.

                      1 Reply Last reply
                      0
                      • S SGaist
                        1 Dec 2015, 15:35

                        MSVC debugger can only be obtained from Microsoft website, here

                        R Offline
                        R Offline
                        Rela
                        wrote on 2 Dec 2015, 13:44 last edited by
                        #36

                        @SGaist
                        I installed Windows SDK and chose all components including "debugging tools for windows". Now, in Tools -> Options -> Build & Run -> Debuggers, I see the two paths for CDB. In "Kit" I chose "Desktop Qt5.5.1 MSVC2013 64bit" and from "Debugger" combo, the CDB.
                        I debug the program with it, and it doesn't give the previous error, but first open the mainwindow.ui and then shows "Debugging starts" in "Application Output" and Compile Output.
                        As I wrote before, instead of adding the (C++code.cpp) file I copied the code in "main.cpp" file to have one main fucntion. The only change I made was that copied the

                        QApplication a(argc, argv);
                            MainWindow w;
                            w.show();
                        

                        After
                        int main(int argc, char *argv[])
                        {
                        in my C++ code. How can I see the results (which are some numbers) in mainwindow.ui?

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 2 Dec 2015, 22:17 last edited by
                          #37

                          Did you implement anything in MainWindow ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          R 1 Reply Last reply 3 Dec 2015, 11:27
                          0
                          • S SGaist
                            2 Dec 2015, 22:17

                            Did you implement anything in MainWindow ?

                            R Offline
                            R Offline
                            Rela
                            wrote on 3 Dec 2015, 11:27 last edited by Rela 12 Mar 2015, 11:44
                            #38

                            @Rela
                            Yes, its an algorithm here written in C++.

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 3 Dec 2015, 12:20 last edited by
                              #39

                              I can't really read it because of all the whited out parts. But the first thing I'd do is check that you don't do anything funky in there. Remove what's not related to your algorithm from main and try to run that. Once it's good, bring back the Qt parts.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              R 1 Reply Last reply 3 Dec 2015, 13:41
                              0
                              • S SGaist
                                3 Dec 2015, 12:20

                                I can't really read it because of all the whited out parts. But the first thing I'd do is check that you don't do anything funky in there. Remove what's not related to your algorithm from main and try to run that. Once it's good, bring back the Qt parts.

                                R Offline
                                R Offline
                                Rela
                                wrote on 3 Dec 2015, 13:41 last edited by Rela 12 Mar 2015, 13:42
                                #40

                                @SGaist
                                Sorry for white space, I have to remove some function names. The algorithm is 2820 lines, and I think each line is needed to output the result. Do you mean i remove the algorithm completely and just remain
                                #include "mainwindow.h"
                                #include <QApplication>
                                int main(int argc, char *argv[])
                                {
                                QApplication a(argc, argv);
                                MainWindow w;
                                w.show();
                                return a.exec();}

                                in main.cpp
                                I did that and the here is the output.

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 3 Dec 2015, 14:21 last edited by
                                  #41

                                  Looks like there's no error there. But I meant the other way around. Run just your algorithm code. The error is there somewhere. And you should put a break point at the start so you can go step by step until it breaks.

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  R 1 Reply Last reply 3 Dec 2015, 14:27
                                  0
                                  • S SGaist
                                    3 Dec 2015, 14:21

                                    Looks like there's no error there. But I meant the other way around. Run just your algorithm code. The error is there somewhere. And you should put a break point at the start so you can go step by step until it breaks.

                                    R Offline
                                    R Offline
                                    Rela
                                    wrote on 3 Dec 2015, 14:27 last edited by
                                    #42

                                    @SGaist
                                    The algorithm code gives result in MSVC2013.

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on 3 Dec 2015, 16:54 last edited by
                                      #43

                                      Then there's something fishy going on with MinGW or you're lucky with Visual Studio. Without any code I can't possibly help you find why it's crashing only with MinGW.

                                      Interested in AI ? www.idiap.ch
                                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      R 1 Reply Last reply 4 Dec 2015, 14:41
                                      0
                                      • S SGaist
                                        3 Dec 2015, 16:54

                                        Then there's something fishy going on with MinGW or you're lucky with Visual Studio. Without any code I can't possibly help you find why it's crashing only with MinGW.

                                        R Offline
                                        R Offline
                                        Rela
                                        wrote on 4 Dec 2015, 14:41 last edited by
                                        #44

                                        @SGaist
                                        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.
                                        main.cpp
                                        Bucky9.cpp
                                        stdafx.cpp
                                        targetver.h
                                        stdafx.h
                                        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:
                                        main.cpp
                                        mainwindow.cpp
                                        stdafx.cpp
                                        stdafx.h
                                        targetver.h
                                        mainwindow.h

                                        When I debug it it start debugging and when I click on Run it gives the "Hello world" in "Application output" here
                                        Now I just want to get the "Hello world" in "mainwindow.ui" instead of in "Application output". Could you tell me how to do that?

                                        1 Reply Last reply
                                        0
                                        • S Offline
                                          S Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on 4 Dec 2015, 21:47 last edited by
                                          #45

                                          First thing: don't use cout since it will send the text to the console.

                                          You can simply put a QLabel with hello world as text as central widget of your MainWindow class.

                                          Interested in AI ? www.idiap.ch
                                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                          R 2 Replies Last reply 8 Dec 2015, 14:08
                                          0

                                          35/123

                                          2 Dec 2015, 10:34

                                          • Login

                                          • Login or register to search.
                                          35 out of 123
                                          • First post
                                            35/123
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved