简体   繁体   中英

Failling Qt application on Ubuntu

I have Ubuntu 10.04 and have the Qt library install. When I run the code

#include <QDir>
#include <QFileInfo>

#include <QtDebug>

int main( int argc, char **argv )
{
    foreach( QFileInfo drive, QDir::drives() )
    {
        qDebug() << "Drive: " << drive.absolutePath();

        QDir dir = drive.dir();
        dir.setFilter( QDir::Dirs );

        foreach( QFileInfo rootDirs, dir.entryInfoList() )
            qDebug() << "  " << rootDirs.fileName();
    }

    return 0;
}

I get the following errors.

g++ qt.cpp -o test
qt.cpp:1:16: error: QDir: No such file or directory
qt.cpp:2:21: error: QFileInfo: No such file or directory
qt.cpp:4:19: error: QtDebug: No such file or directory
qt.cpp: In function ‘int main(int, char**)’:
qt.cpp:8: error: ‘QFileInfo’ was not declared in this scope
qt.cpp:8: error: ‘QDir’ has not been declared
qt.cpp:8: error: ‘foreach’ was not declared in this scope
qt.cpp:9: error: expected ‘;’ before ‘{’ token

How do I fix this problem?

g++ seems to not find Qt includes files.

You should add an include directory when compiling. and linked with the Qt library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM