gpt4 book ai didi

c++ - Ubuntu 上的 Qt 应用程序失败

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:02:06 25 4
gpt4 key购买 nike

我有 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

我该如何解决这个问题?

最佳答案

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

编译时应该添加一个include目录。并链接到 Qt 库。

关于c++ - Ubuntu 上的 Qt 应用程序失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3595547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com