[英]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
statemachine。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.