6

I am working with Qt Creator on Windows Vista. I am trying to compile very simple ".cpp" code that includes the standard C++ library "iostream", like this:

#include <iostream>
using namespace std;

int main(){
    cout << "thanks";
    return 0;
}

The problem comes even before compiling the code. It comes when Qt highlights the library and acknowledge me that (iostream: no such file or directory).

It was working fine a couple of days ago, but then I installed Visual Studio 2012 Express which I then uninstalled because, surprisingly, it does not work with Windows Vista. Immediately after the removal of Visual Studio 2012, C++ libraries are not seen by Qt Creator any more.

Note that I can still compile and run my previous written code by a command-line console, which means C++ libraries haven't been removed with the removal of Visual Studio 2012! In addition, all my previous code (within old projects which were created using the same Qt) has no such problem (i.e., Qt identifies and sees the standard libraries), and I can still compile and run them normally using Qt Creator, even when I create a new ".cpp" file within those old projects:

Enter image description here

However, when I create a new ".cpp" file within a totally new project, libraries disappear and a link is missing:

Enter image description here

(I don't want to get used to reinstall Qt each time I have a similar problem with the compiler, I would like to understand why this is happening in the first place.)

So, what exactly is Qt looking for (or where I should be looking at)?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
McLan
  • 2,552
  • 9
  • 51
  • 85
  • Does it compile when compiling from Qt Creator? – Joseph Mansfield Apr 08 '13 at 21:06
  • @sftrabbit: No, I can't compile it .. besides, Run and Debug buttons are both inactive – McLan Apr 08 '13 at 21:10
  • 1
    Sounds to me like uninstalling Visual Studio took your C++ toolchains with it. You might want to reinstall your Qt SDK. – Phlucious Apr 08 '13 at 21:14
  • You can check in the options of Qt Creator which version of Qt is used. You should verify it, and/or change to another version you have on your computer. You can also reinstall Qt. – Synxis Apr 08 '13 at 21:16
  • @Synxis: My Qt creator version is 2.6.2 (based on Qt 5.0.1), but since I can read it from my Qt creator help it means it is already been verified, isn't it ? – McLan Apr 08 '13 at 21:33
  • "Tools->Options->Build & Run->Compilers" - is there any correct compiler? – Amartel Apr 09 '13 at 04:03
  • @Amartel: the compiler is "MinGW 4.7 32bit MinGW" which is "Auto-detected" .. – McLan Apr 09 '13 at 16:56
  • What about kits? Are there more than one? Which one is used to build your new project and which one is used for building the old ones? Try to compare your old and new projects' settings. Also you can try a little test - open cmd in your project's directory and type "qmake & make". If it builds your project - the problem is in QtCreator, if not - most likely removing VS broke some important paths - include, or libs... – Amartel Apr 09 '13 at 17:17
  • @Amartel: the Kits shows: "Desktop Qt 5.0.1 MinGW 32bit (default)" .. everything between the old and new project seems identical .. I typed "qmake & make" in cmd and the returning output is: (qmake is not recognized as an internal or external command, operable program or batch file. make: *** No target specified and no makefile found. Stop.) so, what does this statement mean? and if paths are broken, where are they exactly? and how to put the right paths (because I can't see where I can do that in Qt, unless you mean in the "Environment variable") – McLan Apr 09 '13 at 21:19
  • To run qmake in cmd you just need to add path to `qmake.exe` to your system `PATH` environment variable. Unfortunately that's not the issue. If your project won't build from cmd, I'm afraid, I don't know how to fix it, except reinstalling Qt SDK. – Amartel Apr 10 '13 at 04:27
  • On screenshot qtcreator fails to find , have you tried ? C++ standard library headers don't have .h at the end. – Pustovalov Dmitry Jan 28 '16 at 15:20

3 Answers3

3

You don't need to reinstall Qt Creator. If you want to use it for running C++ source code, you should first create a project file. Do as follows:

Menu FileNew file or projectNon-Qt projectPlain C++ application.

So that you create a .pro file. Then Qt Creator will be able to find library files <iostream> and the like. See Qt Creator can't find headers (says: "No such file or directory") for a detailed explanation.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user123
  • 231
  • 2
  • 12
  • 2
    I did the same. Even #include written automatically, it displays 'iostream: no such file or directory' message with underline for that line. But I can compile and Run my application. – Hareen Laks Jul 04 '16 at 10:05
0

First open your project file (".pro") in Qt Creator and add the following line:

INCLUDEPATH += /usr/include/c++/{gcc_version}/

Then try to use #include <iostream> in your code.

For me, INCLUDEPATH is /usr/include/c++/4.7.3/.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Vadim
  • 21
  • 5
0

This problem occurred to us just after installation of Qt, using an installer of a version supposed to be used with the .NET compiler.

The .NET installation was not complete: C++ development feature was not installed. We completed the .NET installation, restarted Qt and the problem was off: Qt automatically detected the newly installed compiler program and <iostream> was found.

Note that with some machines, we needed to start Qt as administrator in order to make this work.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Luc
  • 1
  • 1