Qt 6.1.0 MinGW 包含带有“__imp__ZN13QStateMachine…”的错误

Qt 6.1.0 MinGW Include ERROR with “__imp__ZN13QStateMachine…”

这里我使用的是 Qt Creator,今天当我尝试编译这段代码时,它碰巧导致了一些错误。 代码:

#include "mainwindow.h"

#include <QApplication>
#include <QPushButton>
#include <QGraphicsItem>

#include <QtStateMachine/QState>
#include <QtStateMachine/QStateMachine>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QPushButton button("State Machine");
    QStateMachine machine;
    QState* s1 = new QState(&machine);
    QState* s2 = new QState(&machine);
    QState* s3 = new QState(&machine);
    s1->assignProperty(&button, "geometry", QRect(100, 100, 100, 50));
    s2->assignProperty(&button, "geometry", QRect(300, 100, 100, 50));
    s3->assignProperty(&button, "geometry", QRect(200, 200, 100, 50));

    s1->addTransition(&button, SIGNAL(clicked()), s2);
    s2->addTransition(&button, SIGNAL(clicked()), s3);
    s3->addTransition(&button, SIGNAL(clicked()), s1);

    machine.setInitialState(s1);
    machine.start();
    button.show();

    return a.exec();
}

错误如下

D:\Users\STRING10\Documents\QtProjects\build-QStateMachineTest-Desktop_Qt_6_1_0_MinGW_64_bit-Debug..\QStateMachineTest\main.cpp:15: error: undefined reference to \`__imp__ZN13QStateMachineC1EP7QObject' debug/main.o: In function \`qMain(int, char**)': D:\Users\STRING10\Documents\QtProjects\build-QStateMachineTest-Desktop_Qt_6_1_0_MinGW_64_bit-Debug/../QStateMachineTest/main.cpp:15: undefined reference to \`__imp__ZN13QStateMachineC1EP7QObject'

我试图找出我是否错过了存储库,但它确实存在于我的计算机中,并且我将编译器设置为 MinGW,它确实有一个名为 QState 的存储库。

这是我的 .pro:

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp \
    mainwindow.cpp

HEADERS += \
    mainwindow.h

FORMS += \
    mainwindow.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

在Qt6中QStateMachine(以及其他类似的类)属于QtStateMachine子模块,不再属于QtCore子模块,所以在.pro中添加QT += statemachine