c++ - mingw32的Qt编译错误

标签 c++ qt mingw32

我从几天开始就开始使用 qt 进行开发。我想制作一个程序,将鼠标光标移动到我决定的某些位置,但是当我编译最简单的程序时,mingw32 会打印出这个错误:

error: undefined reference to `_imp___ZN15QGuiApplicationC1ERiPPci'
error: undefined reference to `_imp___ZN7QCursorC1Ev'
error: undefined reference to `_imp___ZN7QCursor6setPosEii'
error: undefined reference to `_imp___ZN15QGuiApplicationD1Ev'
error: undefined reference to `_imp___ZN15QGuiApplicationD1Ev'
release/main.o: bad reloc address 0x13 in section `.eh_frame'
collect2.exe:-1: error: error: ld returned 1 exit status

这是我的代码:

#include <QtGui/QGuiApplication>
#include <QtGui/QCursor>

int main(int argc, char *argv[])
{
    QGuiApplication a(argc, argv);
    QCursor *cur = new QCursor;
    cur->setPos(50,50);
    return 0;

    return a.exec();
}

.pro文件

QT       += core

QT       -= gui

TARGET = untitled
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app


SOURCES += main.cpp

我错了什么???我该如何解决??

我在 Win8 Pro x64 上安装了带有 mingw32 的 Qt 5.1

谢谢

最佳答案

我认为你的项目文件是错误的。

所以你想要一个 GUI 应用程序,但是你删除了 GUI 模块

QT       -= gui

您是否尝试过使用项目启动向导创建此应用程序? 我认为您可能选择了错误的应用程序类型。

编辑

如果你想构建一个没有gui模块的项目,你需要用“-=”运算符排除它。默认情况下,QT 包含核心和图形用户界面,因此以下行将生成一个最小的 Qt 项目:

QT -= gui # Only the core module is used.

所以,你只有核心模块。 来源:http://qt-project.org/doc/qt-4.8/qmake-project-files.html

尝试删除

QT       -= gui

行,因为“请注意,QT 默认包含核心和图形用户界面模块”。查看来源。

关于c++ - mingw32的Qt编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17671734/

相关文章:

c - 为什么 Mingw32 提供的 WinBase.h 不包括 Windows 7 的 `SetProcessDEPPolicy'?

java - 工头找不到java

windows - qt 5.2.0 windows 7 缺少 dll(程序崩溃)

c++ - STL 代码 typedef typename value_type、size_type 等。这些是如何工作的?

c++ - 为什么指向指针的取消引用指针的 std::cout 导致 -fsanitize=address 提示?

c++ - 多个 lua_calls 退出并生成 "C stack overflow"

c++ - QT Creator 没有自动检测 MSVC2017 64 位编译器

javascript - 如何将 JavaScript 函数的结果放入 python 变量中。 PyQt

c++ - 以编程方式计算 Windows 上进程的开始时间

c++ - 使用 QProgressBar : Cannot create children for a parent that is in a different thread 时