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?
Forum Updated to NodeBB v4.3 + New Features

How to run a C++ code in Qt?

Scheduled Pinned Locked Moved Installation and Deployment
123 Posts 5 Posters 113.2k Views 3 Watching
  • 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #17

    You have two main functions that are being compiled. Aren't you trying to include too much files in your new project ?

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

    RelaR 1 Reply Last reply
    0
    • SGaistS SGaist

      You have two main functions that are being compiled. Aren't you trying to include too much files in your new project ?

      RelaR Offline
      RelaR Offline
      Rela
      wrote on last edited by Rela
      #18

      @SGaist
      I have these header and cpp files in my C++ code. C++ code
      and add these files to the PS4 Qt project using “Add existing Files”: PS4 Qt

      I also copy the text model (M7) file in the Qt directory and the code reads the data file. I gives the path of the model file using "Argument" in “Desktop Qt5.5 MinGW" run. Previously, I had Qt5.4 and MSVC 2010 and the results including some numbers appeared in "Application Output". Now, using Qt5.5 and MSVC 2013, the “Desktop Qt5.5 MinGW" works without error, but the "Application Output" shows this result, which are zero, instead of some non-zero numbers (cpu and z). Application output

      However, when I compile with "Desktop Qt MSVC2013 64bit", it gives these errors: Issues
      Compile output
      Even if it gives the results using “Desktop Qt5.5 MinGW", it is ok, but it does not.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #19

        Again, you have multiple main function, that's the first problem to solve. Why do you have more than one ?

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

        RelaR 1 Reply Last reply
        0
        • SGaistS SGaist

          Again, you have multiple main function, that's the first problem to solve. Why do you have more than one ?

          RelaR Offline
          RelaR Offline
          Rela
          wrote on last edited by
          #20

          @SGaist
          You mean the "main.cpp" and "mainwindow.cpp" ?
          If so, this is the same I did before with Qt5.4.1. There were the same main functions and gave the results in "Application Output".
          I create a new project in Qt creator:
          “New Project” >> “Qt Widgets Application” >> (Class name) “MainWindow” & (Base class) "QMainWindow" >> "Next" and "Finish" this application window:New Project
          After that I added .cpp and .h files of the C++ code using “Add existing Files”.

          1 Reply Last reply
          0
          • jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #21

            SGaist means the C/C++ main function:

            int main(int argc, char** argv)
            {
            ...
            }
            

            An application can only have one main function, as the compiler error says you have two of them.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • RelaR Offline
              RelaR Offline
              Rela
              wrote on last edited by Rela
              #22

              I have one "int main(int argc, char argv[])
              { ..."* function in "O_PS .cpp" file, and one main function in "main.cpp" file. Qt

              jsulmJ 1 Reply Last reply
              0
              • RelaR Rela

                I have one "int main(int argc, char argv[])
                { ..."* function in "O_PS .cpp" file, and one main function in "main.cpp" file. Qt

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #23

                @Rela You should remove one of them.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                RelaR 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Rela You should remove one of them.

                  RelaR Offline
                  RelaR Offline
                  Rela
                  wrote on last edited by Rela
                  #24

                  @jsulm
                  Could you explain how? The main function of "O_PS .cpp" is my C++ code, do I delete:
                  int main(int argc, char *argv[])
                  {
                  QApplication a(argc, argv);
                  MainWindow w;
                  w.show();

                  return a.exec();
                  

                  } in "main.cpp" ?

                  1 Reply Last reply
                  0
                  • jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #25

                    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.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    RelaR 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      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.

                      RelaR Offline
                      RelaR Offline
                      Rela
                      wrote on 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
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 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

                        RelaR 1 Reply Last reply
                        0
                        • SGaistS SGaist

                          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.

                          RelaR Offline
                          RelaR Offline
                          Rela
                          wrote on last edited by Rela
                          #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
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 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

                            RelaR 2 Replies Last reply
                            0
                            • SGaistS SGaist

                              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.

                              RelaR Offline
                              RelaR Offline
                              Rela
                              wrote on last edited by
                              #30
                              This post is deleted!
                              1 Reply Last reply
                              0
                              • SGaistS SGaist

                                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.

                                RelaR Offline
                                RelaR Offline
                                Rela
                                wrote on 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
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 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

                                  RelaR 1 Reply Last reply
                                  0
                                  • SGaistS SGaist

                                    You need to install the debugger for MSVC

                                    RelaR Offline
                                    RelaR Offline
                                    Rela
                                    wrote on 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
                                    • SGaistS Offline
                                      SGaistS Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on 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

                                      RelaR 2 Replies Last reply
                                      0
                                      • SGaistS SGaist

                                        MSVC debugger can only be obtained from Microsoft website, here

                                        RelaR Offline
                                        RelaR Offline
                                        Rela
                                        wrote on 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
                                        • SGaistS SGaist

                                          MSVC debugger can only be obtained from Microsoft website, here

                                          RelaR Offline
                                          RelaR Offline
                                          Rela
                                          wrote on 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

                                          • Login

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