我将qt下载到我的计算机中,并以#include<QDir>的形式调用QDir。但它会出现错误fatal error: QDir: No such file or directory。有没有在不创建.pro文件的情况下使用QDir的方法?
我尝试创建一个.pro文件:
Template += app
QT += core
Source += src.cpp但是它不起作用。
#include <QDir>
src.cpp:1:16: fatal error: QDir: No such file or directory发布于 2019-07-13 16:26:15
构建src.cpp的最小.pro文件,假设您在其中也有main函数:
SOURCES += src.cpp请使用Qt Creator新建项目向导为您创建.pro文件(或CMake的cmakelist.txt),或者使用已知良好的示例/模板开始,这样您就可以获得正确的一切。你不想在没有makefile生成器的情况下使用像Qt这样的复杂框架!但如果真的必须这样做,可以使用qmake (或cmake)生成一次makefile,然后删除.pro文件并继续编辑makefile。只需注意,如果没有大量的额外工作,它可能不会对任何人起作用,除了你。所以别去那了。
完整的使用QDir的工作示例:
.pro文件:
# core and gui are defaults, remove gui
QT -= gui
# cmdline includes console for Win32, and removes app_bundle for Mac
CONFIG += cmdline
# there should be no reason to not use C++14 today
CONFIG += c++14
# enable more warnings for compiler, remember to fix them
CONFIG += warn_on
# this is nice to have
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp示例main.cpp
#include <QDir>
#include <QDebug> // or use std::cout etc
//#include <QCoreApplication>
int main(int argc, char *argv[])
{
// for most Qt stuff, you need the application object created,
// but this example works without
//QCoreApplication app(argc, argv);
for(auto name : QDir("/").entryList()) {
qDebug() << name;
}
// return app.exec(); // don't start event loop (main has default return 0)
}https://stackoverflow.com/questions/57015086
复制相似问题