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.1k 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 19 Feb 2016, 22:40 last edited by
    #100

    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.

    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 Feb 2016, 10:07
    0
    • S SGaist
      19 Feb 2016, 22:40

      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.

      R Offline
      R Offline
      Rela
      wrote on 22 Feb 2016, 10:07 last edited by
      #101

      @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```

       "targetver.h"
      #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.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 22 Feb 2016, 11:08 last edited by
        #102

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

        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 Feb 2016, 11:34
        0
        • S SGaist
          22 Feb 2016, 11:08

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

          R Offline
          R Offline
          Rela
          wrote on 22 Feb 2016, 11:34 last edited by
          #103

          @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?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 22 Feb 2016, 20:18 last edited by
            #104

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

            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 Feb 2016, 08:21
            0
            • S SGaist
              22 Feb 2016, 20:18

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

              R Offline
              R Offline
              Rela
              wrote on 23 Feb 2016, 08:21 last edited by Rela
              #105

              @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

              K 1 Reply Last reply 23 Feb 2016, 08:36
              0
              • R Rela
                23 Feb 2016, 08:21

                @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

                K Offline
                K Offline
                kshegunov
                Moderators
                wrote on 23 Feb 2016, 08:36 last edited by kshegunov
                #106

                @Rela
                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.

                Read and abide by the Qt Code of Conduct

                R 1 Reply Last reply 23 Feb 2016, 10:19
                0
                • K kshegunov
                  23 Feb 2016, 08:36

                  @Rela
                  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.

                  R Offline
                  R Offline
                  Rela
                  wrote on 23 Feb 2016, 10:19 last edited by Rela
                  #107

                  @kshegunov
                  There are

                  using namespace std;
                  #include <iostream>
                  #include <fstream>
                  #include <ostream>
                  

                  in the "main.cpp" already. I added ```

                  #include <stdio.h>
                  

                  in each file, but it gave the same error.

                  K 1 Reply Last reply 23 Feb 2016, 10:25
                  0
                  • R Rela
                    23 Feb 2016, 10:19

                    @kshegunov
                    There are

                    using namespace std;
                    #include <iostream>
                    #include <fstream>
                    #include <ostream>
                    

                    in the "main.cpp" already. I added ```

                    #include <stdio.h>
                    

                    in each file, but it gave the same error.

                    K Offline
                    K Offline
                    kshegunov
                    Moderators
                    wrote on 23 Feb 2016, 10:25 last edited by kshegunov
                    #108

                    @Rela said:

                    There are ... in the "main.cpp" already.

                    But obviously these headers are not present in mainwindow.h, whence the compile errors. The compiler doesn't know heck about ostream when processing the mainwindow.h and it's whining ...

                    Kind regards.

                    Read and abide by the Qt Code of Conduct

                    R 1 Reply Last reply 23 Feb 2016, 12:12
                    0
                    • K kshegunov
                      23 Feb 2016, 10:25

                      @Rela said:

                      There are ... in the "main.cpp" already.

                      But obviously these headers are not present in mainwindow.h, whence the compile errors. The compiler doesn't know heck about ostream when processing the mainwindow.h and it's whining ...

                      Kind regards.

                      R Offline
                      R Offline
                      Rela
                      wrote on 23 Feb 2016, 12:12 last edited by
                      #109

                      @kshegunov
                      Thanks. Do you know what else I can do except adding ```

                      #include <stdio.h>
                      

                      to the "mainwindow.h"?

                      K 1 Reply Last reply 23 Feb 2016, 12:16
                      0
                      • R Rela
                        23 Feb 2016, 12:12

                        @kshegunov
                        Thanks. Do you know what else I can do except adding ```

                        #include <stdio.h>
                        

                        to the "mainwindow.h"?

                        K Offline
                        K Offline
                        kshegunov
                        Moderators
                        wrote on 23 Feb 2016, 12:16 last edited by
                        #110

                        @Rela

                        Add the aforementioned headers to the mainwindow.h:

                        #include <iostream>
                        #include <fstream>
                        #include <ostream>
                        
                        using namespace std;
                        

                        Otherwise the compiler will not know what ostream is.

                        Read and abide by the Qt Code of Conduct

                        R 1 Reply Last reply 23 Feb 2016, 12:48
                        0
                        • K kshegunov
                          23 Feb 2016, 12:16

                          @Rela

                          Add the aforementioned headers to the mainwindow.h:

                          #include <iostream>
                          #include <fstream>
                          #include <ostream>
                          
                          using namespace std;
                          

                          Otherwise the compiler will not know what ostream is.

                          R Offline
                          R Offline
                          Rela
                          wrote on 23 Feb 2016, 12:48 last edited by
                          #111

                          @kshegunov
                          Done, but here are the errors cleaned again ;)

                          K 1 Reply Last reply 23 Feb 2016, 12:57
                          0
                          • R Rela
                            23 Feb 2016, 12:48

                            @kshegunov
                            Done, but here are the errors cleaned again ;)

                            K Offline
                            K Offline
                            kshegunov
                            Moderators
                            wrote on 23 Feb 2016, 12:57 last edited by
                            #112

                            @Rela
                            I'm sorry but I have no idea what's happening, with the deletions and without a complete code snippet this is just turning into a guessing game. Not to mention the preprocessor directives, whose expansions I have no way of deducing. The errors have obviously changed and they are at compile-time, so focus on that and try to resolve the type mismatches.

                            Read and abide by the Qt Code of Conduct

                            R 1 Reply Last reply 23 Feb 2016, 13:31
                            0
                            • K kshegunov
                              23 Feb 2016, 12:57

                              @Rela
                              I'm sorry but I have no idea what's happening, with the deletions and without a complete code snippet this is just turning into a guessing game. Not to mention the preprocessor directives, whose expansions I have no way of deducing. The errors have obviously changed and they are at compile-time, so focus on that and try to resolve the type mismatches.

                              R Offline
                              R Offline
                              Rela
                              wrote on 23 Feb 2016, 13:31 last edited by
                              #113

                              @kshegunov
                              The problem is not related to the code. The C++ code works properly in MV and also it worked in Qt creator before and gave the results in "Application Outputs" with Qt5.5 and MV 2013. The problem happened, when I start working with MV 2015 and Qt5.6 beta.
                              I just did the previous way and added all C++ files to the Qt project files. Do you have any idea about the ```

                              error: dependent '..\C++' does not exist.
                              
                              K 1 Reply Last reply 23 Feb 2016, 13:41
                              0
                              • R Rela
                                23 Feb 2016, 13:31

                                @kshegunov
                                The problem is not related to the code. The C++ code works properly in MV and also it worked in Qt creator before and gave the results in "Application Outputs" with Qt5.5 and MV 2013. The problem happened, when I start working with MV 2015 and Qt5.6 beta.
                                I just did the previous way and added all C++ files to the Qt project files. Do you have any idea about the ```

                                error: dependent '..\C++' does not exist.
                                
                                K Offline
                                K Offline
                                kshegunov
                                Moderators
                                wrote on 23 Feb 2016, 13:41 last edited by
                                #114

                                @Rela
                                I have never seen that error, but if I had to guess probably a folder can't be found by qmake. Inspect your project file, and make sure all folders/files exist. Then rerun qmake and then do a full rebuild. Additionally, don't use backslashes for your paths when working with qmake, use *nix-style paths, for example: C:/somefolder/somefile.cpp

                                Read and abide by the Qt Code of Conduct

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 23 Feb 2016, 20:41 last edited by
                                  #115

                                  Do you have something containing "C++" anywhere in your .pro 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 24 Feb 2016, 13:51
                                  0
                                  • S SGaist
                                    23 Feb 2016, 20:41

                                    Do you have something containing "C++" anywhere in your .pro file ?

                                    R Offline
                                    R Offline
                                    Rela
                                    wrote on 24 Feb 2016, 13:51 last edited by
                                    #116

                                    @SGaist
                                    Yes, I had something like this in PS8, because I added the C++ project header and source files through the "../C++ projects/po... /" path. But, now I removed the space of "C++ projects" (because maybe it makes problem), and changed the path withoutspace. PS10 Qt project .pro file is this
                                    Now the error is this

                                    1 Reply Last reply
                                    0
                                    • J Offline
                                      J Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on 25 Feb 2016, 06:37 last edited by
                                      #117

                                      What is char.h?

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

                                      R 1 Reply Last reply 25 Feb 2016, 11:15
                                      0
                                      • J jsulm
                                        25 Feb 2016, 06:37

                                        What is char.h?

                                        R Offline
                                        R Offline
                                        Rela
                                        wrote on 25 Feb 2016, 11:15 last edited by Rela
                                        #118

                                        @jsulm
                                        It was

                                        #include <tchar.h>
                                        

                                        in the C++ code, but it had given the errors like

                                        'void PS... (char *)': cannot convert argument 1 from 'const char [37]' to 'char *'
                                        

                                        and I changed it to "char".
                                        I think its related to the main function in "main.cpp"

                                        int main(int argc, char* argv[])
                                        {
                                        
                                        K 1 Reply Last reply 25 Feb 2016, 12:10
                                        0
                                        • J Offline
                                          J Offline
                                          jsulm
                                          Lifetime Qt Champion
                                          wrote on 25 Feb 2016, 11:47 last edited by
                                          #119

                                          How is it related to main?
                                          char is a native data type in C and C++, you do not have to include any header file to use it. So just remove this include.
                                          This error:

                                          'void PS... (char *)': cannot convert argument 1 from 'const char [37]' to 'char *'
                                          

                                          You got probably because you're passing a const char string as parameter to a function which expects a non const char string:

                                          void PS... (char *param);
                                          then you call
                                          PS...("a string");
                                          

                                          Do it like this:

                                          char *param = "a string";
                                          PS...(param);
                                          

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

                                          1 Reply Last reply
                                          0

                                          109/123

                                          23 Feb 2016, 12:12

                                          • Login

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