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?
QtWS25 Last Chance

How to run a C++ code in Qt?

Scheduled Pinned Locked Moved Installation and Deployment
123 Posts 5 Posters 108.3k 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 21 Oct 2015, 21:05 last edited by
    #6

    Just pass the path to your file (including the file name)

    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 22 Oct 2015, 06:10
    0
    • S SGaist
      21 Oct 2015, 21:05

      Just pass the path to your file (including the file name)

      R Offline
      R Offline
      Rela
      wrote on 22 Oct 2015, 06:10 last edited by
      #7

      @SGaist
      It is not possible just pass the path, because when I go to Run part of the project panel and click on the "Argument" option ("AB..."), It asks the variable, and the window is opened. Argument

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 22 Oct 2015, 10:12 last edited by
        #8

        Don't click on the icon, write the path by hand to your file

        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 22 Oct 2015, 10:47
        0
        • S SGaist
          22 Oct 2015, 10:12

          Don't click on the icon, write the path by hand to your file

          R Offline
          R Offline
          Rela
          wrote on 22 Oct 2015, 10:47 last edited by
          #9

          @SGaist
          I did it like this: File path, but it gives the same error:
          Starting C:\Qt\Tutorials\PS\build-ps1-Desktop_Qt_5_4_2_MinGW_32bit-Release\release\ps1.exe...
          Invalid parameter passed to C runtime function.
          Invalid parameter passed to C runtime function.
          terminate called after throwing an instance of 'std::bad_alloc'
          what(): std::bad_alloc
          C:\Qt\Tutorials\PS\build-ps1-Desktop_Qt_5_4_2_MinGW_32bit-Release\release\ps1.exe exited with code 3

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 22 Oct 2015, 11:55 last edited by
            #10

            You're missing the file extension

            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 23 Oct 2015, 11:13
            1
            • S SGaist
              22 Oct 2015, 11:55

              You're missing the file extension

              R Offline
              R Offline
              Rela
              wrote on 23 Oct 2015, 11:13 last edited by Rela
              #11

              @SGaist
              Thanks, it worked and gives the results in "Application Output". Now, I want to enter the text file data using "mainwindow.ui" instead of reading the text file. Does it need to change the code or I should just add some functions to the "mainwindow.cpp" for Objects in "mainwindow.ui"?
              For this model data, these were defined in cpp file:
              "bool ReadModelData(istream &in, Master &_MS)"

              and the ReadModelData is called with:

              "fin.open(argv[1],ios::in);
              fin >> nof_people;
              for(i=0; i<nof_people; i++) {
              ReadModelData(fin,s);"
              ...
              in header file:
              "bool ReadModelData(istream &, Master &);"

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

                Add a function in your MainWindow class that takes the path as a const QString & then use QFile to read it and put the content in your text widget.

                Note that you have the nice and handy QCommandLineOption and QCommandLineParser classes to handle command line option you pass to your application.

                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 26 Oct 2015, 09:25
                0
                • S SGaist
                  23 Oct 2015, 20:15

                  Add a function in your MainWindow class that takes the path as a const QString & then use QFile to read it and put the content in your text widget.

                  Note that you have the nice and handy QCommandLineOption and QCommandLineParser classes to handle command line option you pass to your application.

                  R Offline
                  R Offline
                  Rela
                  wrote on 26 Oct 2015, 09:25 last edited by Rela
                  #13
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • S SGaist
                    16 Oct 2015, 21:51

                    Hi,

                    Please show the complete error log.

                    Qt is a C++ library, so there's nothing special to do regarding that question.

                    R Offline
                    R Offline
                    Rela
                    wrote on 23 Nov 2015, 10:55 last edited by
                    #14

                    @SGaist
                    Hi,
                    I have installed the newer version of Qt5.5.1 and trying to do the same (I have a C++ code, which gives output using MVS2013, and going to develop a stand-alone GUI for it using Qt5.5. I created a new project in Qt creator: ).
                    “New Project” >> “Qt Widgets Application” >> “MainWindow” and added .cpp and .h files of the C++ code using “Add existing Files”.
                    Using previous version Qt5.4.1, I could add all .cpp and .h files from my C++ code using “Add existing Files” with right click on "Headers" and "Sources". It showed the added files like this:
                    Add existing Files
                    But now when I do the same procedure, it doesn't show the new file added.
                    Not added
                    When I run it using "MSVC2013 64bit" , it gives this error: MSVC2013
                    Using "MinGW 32bit" , it gives this error: MinGW
                    Is there another way to add ready C++ code to the Qt5.5.1?

                    1 Reply Last reply
                    0
                    • jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 23 Nov 2015, 12:17 last edited by
                      #15

                      The paths in the error messages look strange: many blanks.
                      Can you post the content of the *.PRO file?

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

                      R 1 Reply Last reply 23 Nov 2015, 15:43
                      0
                      • jsulmJ jsulm
                        23 Nov 2015, 12:17

                        The paths in the error messages look strange: many blanks.
                        Can you post the content of the *.PRO file?

                        R Offline
                        R Offline
                        Rela
                        wrote on 23 Nov 2015, 15:43 last edited by Rela
                        #16

                        @jsulm
                        Sorry for blank spaces, just I have to delete some project names.
                        Now, I have added the headers and cpp files from another path and it shows them:Added existing files
                        The reads a text file data, and I add its path in "Argument" of " MinGW 32 bit" and it gives the results in Application Output.
                        Does it matter from which path I choose the .h and .cpp files, or in which directory the Qt project is saved?
                        However, when I use "Desktop Qt 5.5.1 MSVC2013 64bit" it gives this error: Compile Outputs
                        Issues

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 23 Nov 2015, 16:58 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

                          R 1 Reply Last reply 24 Nov 2015, 08:22
                          0
                          • S SGaist
                            23 Nov 2015, 16:58

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

                            R Offline
                            R Offline
                            Rela
                            wrote on 24 Nov 2015, 08:22 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
                            • S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 24 Nov 2015, 09:43 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

                              R 1 Reply Last reply 25 Nov 2015, 08:50
                              0
                              • S SGaist
                                24 Nov 2015, 09:43

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

                                R Offline
                                R Offline
                                Rela
                                wrote on 25 Nov 2015, 08:50 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 25 Nov 2015, 10:03 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
                                  • R Offline
                                    R Offline
                                    Rela
                                    wrote on 25 Nov 2015, 12:44 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 25 Nov 2015, 13:34
                                    0
                                    • R Rela
                                      25 Nov 2015, 12:44

                                      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 25 Nov 2015, 13:34 last edited by
                                      #23

                                      @Rela You should remove one of them.

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

                                      R 1 Reply Last reply 25 Nov 2015, 13:47
                                      0
                                      • jsulmJ jsulm
                                        25 Nov 2015, 13:34

                                        @Rela You should remove one of them.

                                        R Offline
                                        R Offline
                                        Rela
                                        wrote on 25 Nov 2015, 13:47 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 25 Nov 2015, 13:50 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

                                          R 1 Reply Last reply 25 Nov 2015, 14:21
                                          0

                                          • Login

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