我jsut安装了Qt 4.7.2,我正在尝试使用QLibraryInfo该类.我的问题是QLibraryInfo::location(QLibraryInfo::PrefixPath)总是返回C:\work3\qt-4.7-vs2010-x86我的生成机器上不存在的(应该是C:\Qt\qt-4.7.2).
根据文档,我试图qt.conf在我的程序旁边创建一个文件,但问题仍然存在.这是它的内容:
[Paths]
Prefix=C:/Qt/qt-4.7.2/
Run Code Online (Sandbox Code Playgroud)
现在我用一个符号链接来绕过这个问题,但我想知道是否有一个合适的解决方案.谢谢.
编辑
这是使用以下程序QLibraryInfo:
int main(int argc, char ** argv)
{
QCoreApplication app(argc, argv); //< added after Piotr's suggestion
QFile outf("qtdirs.out");
if (!outf.open(QIODevice::WriteOnly|QIODevice::Truncate|QIODevice::Text))
return 1;
QTextStream out(&outf);
out << QLibraryInfo::location(QLibraryInfo::PrefixPath) << '\n';
out << QLibraryInfo::location(QLibraryInfo::HeadersPath) << '\n';
...
}
Run Code Online (Sandbox Code Playgroud)
必须创建 QCoreApplication,因为这是 QLibraryInfo 能够确定QCoreApplication::applicationDirPath()从中加载 qt.conf 文件的应用程序目录 ( ) 的方式。或者,qt.conf 可以作为资源构建到应用程序中,路径为“:/qt/etc/qt.conf”。