1
我有Ubuntu 10.04並且安裝了Qt庫。當我運行代碼在Ubuntu上Failling 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
如何解決此問題?
第3個錯誤表示編譯器無法找到包含文件。這不是代碼。你的環境出了問題。 – jacknad 2010-08-29 16:30:32
爲什麼不使用'qmake'然後'make'來編譯它?它爲你處理所有這些類型的東西。 – 2010-08-29 17:07:18