【发布时间】:2023-11-05 23:25:01
【问题描述】:
我正在尝试为大学设置 Qt,但遇到了一些问题。我正在运行 Windows 8,我不确定 Qt 或 QtCreator 的哪个版本,但不是最新的 - 我们获得了版本安装程序,所以我们必须使用这个,尽管我确实在 QtCreator 设置之前自己安装了最新的 MinGW。
我在 QtCreator 中尝试了一些演示代码,但在尝试运行以下代码时出现错误“无法识别的命令行选项”-WI。
#include <QtCore/QCoreApplication>
#include <QtGui/QMessageBox>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QMessageBox msgBox;
msgBox.setText("This is some text.");
msgBox.exec();
return a.exec();
}
我需要完成我的任务,当我遇到所有这些奇怪的错误时,我不确定我该怎么做。 任何帮助将不胜感激。
提前致谢!
* 编辑 *
这是我在构建过程中可以在 QtCreator 中找到的错误输出。
Running build steps for project TestProject...
Configuration unchanged, skipping qmake step.
Starting: "C:/MinGW/bin/mingw32-make.exe" -w
mingw32-make: Entering directory 'C:/Users/Nick/Documents/Qt Projects/TestProject-build-desktop'
C:/MinGW/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Users/Nick/Documents/Qt Projects/TestProject-build-desktop'
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -mthreads -Wl -o debug\TestProject.exe debug/main.o -L"c:\Qt\2010.04\qt\lib" -lQtCored4
Makefile.Debug:73: recipe for target 'debug\TestProject.exe' failed
mingw32-make[1]: Leaving directory 'C:/Users/Nick/Documents/Qt Projects/TestProject-build-desktop'
Makefile:34: recipe for target 'debug' failed
mingw32-make: Leaving directory 'C:/Users/Nick/Documents/Qt Projects/TestProject-build-desktop'
g++: error: unrecognized command line option '-Wl'
mingw32-make[1]: *** [debug\TestProject.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "C:/MinGW/bin/mingw32-make.exe" exited with code %2.
Error while building project TestProject (target: Desktop)
When executing build step 'Make'
以下是 QtCreator 生成的 .pro 文件的内容:
QT += core
QT -= gui
TARGET = TestProject
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
【问题讨论】:
-
-Wl是使用 gcc “作为链接器”时传递给链接器的参数。如果没有确切地看到链接器命令是什么,很难确切地说出发生了什么。 -
我怎样才能把那个给你?
-
不确定,我不太使用 Qt。
-
我编辑了问题并添加到控制台输出中,如果对您有帮助的话?
-
您可以通过“关于 Qt Creator”对话框找到 Qt Creator 版本,通过 Preferences->Build & Run->Qt Versions 找到配置的 Qt 版本。此外,您的代码将无法运行,因为QMessageBox 需要一个 QApplication,而不仅仅是一个 QCoreApplication。