1

Here I'm using Qt Creator and today when I tried to compile this code it happened to cause some errors. code:

#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();
}

And the errors are as followed

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'

I have tried to find out if I missed the repository but it really exists in my computer and I have made the compiler as MinGW which do have a repository named QState.

Here's my .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
eyllanesc
  • 190,383
  • 15
  • 87
  • 142
String Max
  • 13
  • 3

1 Answers1

2

In Qt6 QStateMachine (and the other similar classes) belong to the QtStateMachine submodule, no longer to the QtCore submodule, so add QT += statemachine to the .pro.

eyllanesc
  • 190,383
  • 15
  • 87
  • 142