在Ubuntu上下载Qt应用程序

时间:2010-08-29 16:24:00

标签: c++

我有Ubuntu 10.04并安装了Qt库。当我运行代码时

#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;
}

我收到以下错误。

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

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

g ++似乎找不到Qt包含文件。

编译时应添加include目录。并与Qt库链接。