【发布时间】:2011-03-02 10:10:08
【问题描述】:
我只安装了 Qt 4.7.2,我正在尝试使用 QLibraryInfo 类。我的问题是QLibraryInfo::location(QLibraryInfo::PrefixPath) 总是返回C:\work3\qt-4.7-vs2010-x86,这在我的生成机器上不存在(应该是C:\Qt\qt-4.7.2)。
根据the documentation,我尝试在我的程序旁边创建一个qt.conf 文件,但问题仍然存在。以下是它的内容:
[Paths]
Prefix=C:/Qt/qt-4.7.2/
目前我使用符号链接来绕过该问题,但我想知道是否有合适的解决方案。 谢谢。
编辑
这是使用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';
...
}
【问题讨论】:
-
您是从源代码构建 Qt 4.7.2 还是安装了二进制文件?
-
我安装了qt.nokia.com/downloads/windows-cpp-vs2008提供的二进制文件
-
在创建 QApplication/QCoreApplication 之后是否使用 QLibraryInfo?
-
不,QApplication 对象甚至从未被创建。该应用程序的唯一目的是将 Qt 路径写入文件。这是构建 PyQt 的配置脚本的第一步。
-
这就是问题所在。你至少需要 QCoreApplication 才能工作。