Important: Please read the Qt Code of Conduct -

I'm unable to compile my first programme it says "/usr/local/qt4/include/QtCore/qstring.h:54:20: fatal error: string: No such file or directory"

  • Hello i'm new to qt i'm just rying to compile an example code but it show error here is my code @#include <QtGui/QApplication>
    #include <QtGui/QWidget>

    int main(int argc, char *argv[])
    QApplication app(argc, argv);

    QWidget window;
    window.resize(250, 150);
    window.setWindowTitle("Simple example");;
    return app.exec();

    }@ HERE IS THE ERROR @In file included from /usr/local/qt4/include/QtCore/qobject.h:48:0,
    from /usr/local/qt4/include/QtCore/qcoreapplication.h:45,
    from /usr/local/qt4/include/QtGui/qapplication.h:45,
    from /usr/local/qt4/include/QtGui/QApplication:1,
    from n_0.c:1:
    /usr/local/qt4/include/QtCore/qstring.h:54:20: fatal error: string: No such file or directory

    include <string>


    compilation terminated.
    make: *** [n_0.o] Error 1
    @ THIS ERROR IS QUITE BIG BUT I PASTED only the essential part needed to solve my problem here

  • add
    #include <QString>


  • I suspect the problem is in your environment.
    I tested this with Qt 4.84, msvc 10, on Win7. and it compiled
    and ran as expected.

    Here is my .pro file
    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = test
    TEMPLATE = app

    SOURCES += main.cpp

  • Moderators

    Hi, and welcome to the Qt Dev Net!

    The Qt header <qstring.h> tries to include the standard C++ header <string>. The error messages show that your compiler could not find <string>.

    You need to install the standard C++ development files in your system.

    If you need more help, please tell us:

    What distro are you using?

    How did you install your compiler?

  • thanks a lot fellas ! problem solved , actually my source file was having .c extension i changed it to .cpp and it worked !

Log in to reply