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 109.1k 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.
  • jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #91

    See here: http://stackoverflow.com/questions/4726155/whats-the-use-for-stdafx-h-in-visual-studio
    stdafx.h seems to be generated by VS, so you should not use it with MinGW

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

    RelaR 1 Reply Last reply
    0
    • jsulmJ jsulm

      See here: http://stackoverflow.com/questions/4726155/whats-the-use-for-stdafx-h-in-visual-studio
      stdafx.h seems to be generated by VS, so you should not use it with MinGW

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

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

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

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

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

          Please take a look at error messages you get:

          "\\home.org.a\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.

          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
            #95

            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>
            

            to

            #inclu```de <char.h>
            

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

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

            errors.

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

              Could you please reply me?

              1 Reply Last reply
              0
              • RelaR Rela

                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>
                

                to

                #inclu```de <char.h>
                

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

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

                errors.

                the_T Offline
                the_T Offline
                the_
                wrote on last edited by
                #97

                @Rela

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

                -- No support in PM --

                RelaR 1 Reply Last reply
                0
                • the_T the_

                  @Rela

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

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

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

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

                    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:
                    O_PS.H
                    stdafx.h
                    targetver.h
                    O_PS.CPP
                    ps.cpp
                    stdafx.cpp

                    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.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 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

                      RelaR 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        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.

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

                          RelaR 1 Reply Last reply
                          0
                          • SGaistS SGaist

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

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

                              RelaR 1 Reply Last reply
                              0
                              • SGaistS SGaist

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

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

                                kshegunovK 1 Reply Last reply
                                0
                                • RelaR Rela

                                  @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

                                  kshegunovK Offline
                                  kshegunovK Offline
                                  kshegunov
                                  Moderators
                                  wrote on 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

                                  RelaR 1 Reply Last reply
                                  0
                                  • kshegunovK kshegunov

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

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

                                    kshegunovK 1 Reply Last reply
                                    0
                                    • RelaR Rela

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

                                      kshegunovK Offline
                                      kshegunovK Offline
                                      kshegunov
                                      Moderators
                                      wrote on 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

                                      RelaR 1 Reply Last reply
                                      0
                                      • kshegunovK kshegunov

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

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

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

                                        #include <stdio.h>
                                        

                                        to the "mainwindow.h"?

                                        kshegunovK 1 Reply Last reply
                                        0
                                        • RelaR Rela

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

                                          #include <stdio.h>
                                          

                                          to the "mainwindow.h"?

                                          kshegunovK Offline
                                          kshegunovK Offline
                                          kshegunov
                                          Moderators
                                          wrote on 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

                                          RelaR 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