How to run a C++ code in Qt?
-
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.cppand 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. -
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.
-
@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.
-
You have to fix the includes in your O_PS* files so add the missing
#include <stdio.h>
-
No, include them in your O_PS* files where suited.
-
@Rela
It must have taken you ages to delete those names ... Anyway, to useostream
,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 thestd
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.
-
@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 aboutostream
when processing themainwindow.h
and it's whining ...Kind regards.
-
@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. -
@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.
-
@Rela
I have never seen that error, but if I had to guess probably a folder can't be found byqmake
. Inspect your project file, and make sure all folders/files exist. Then rerunqmake
and then do a full rebuild. Additionally, don't use backslashes for your paths when working withqmake
, use *nix-style paths, for example:C:/somefolder/somefile.cpp
-
Do you have something containing "C++" anywhere in your .pro file ?
-
@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 -
What is char.h?
-
@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[]) {