【问题标题】:Qt compilation error with mingw32mingw32的Qt编译错误
【发布时间】:2013-07-16 08:35:39
【问题描述】:

我从几天开始就开始使用 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

谢谢

【问题讨论】:

    标签: c++ qt mingw32


    【解决方案1】:

    我认为你的项目文件有误。

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

    QT       -= gui
    

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

    编辑

    如果您想构建一个没有 gui 模块的项目,您需要使用“-=”运算符将其排除。默认情况下,QT 包含 core 和 gui,因此下面这行将导致构建一个最小的 Qt 项目:

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

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

    尝试删除

    QT       -= gui
    

    行,因为“请注意,QT 默认包含核心和 gui 模块”。见源代码。

    【讨论】:

    • 谢谢,我在使用向导创建项目时出错。我觉得自己像个菜鸟:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多