PDA

View Full Version : SCXML and QScxmlCppDataModel cause a segmentation fault



bouchebeu
27th December 2017, 10:57
Hello everyone,

I'm using the QScxmlStateMachine and wanted to use the QScxmlCppDataModel.
I copied the "mediaplayer-qml-cppdatamodel" example and executed it without any problem.

Since I'm not using QML, i replaced the main function with the following:



int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QScxmlStateMachine* machine = new MediaPlayerStateMachine() ;

machine->start();

return a.exec();
}


Unfortunately, I get a segmentation fault that I remove when I comment the line (in my .scxml) datamodel="cplusplus:TheDataModel:thedatamodel.h".

I also tried to simply add the QScxmlStateMachine instantiation and starting inside the original main function but it still fails.



int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);

qmlRegisterType<TheDataModel>("MediaPlayerDataModel", 1, 0, "MediaPlayerDataModel");
qmlRegisterType<MediaPlayerStateMachine>("MediaPlayerStateMachine", 1, 0, "MediaPlayerStateMachine");

QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:///mediaplayer-qml-cppdatamodel.qml")));

QScxmlStateMachine* machine = new MediaPlayerStateMachine() ;
machine->start();

return app.exec();
}



Launching in debug gives only the line where the error occurs which is return app.exec();

Does it ring a bell to anyone?


Thanks.

Qt5.7.1 on linux 64

bouchebeu
27th December 2017, 14:11
Ok, found where the issue is.

I forgot to set the data model; in QML example:


Mediaplayer {
MediaPlayerDataModel {
id: model
}

stateMachine: MediaPlayerStateMachine {
onDataModelChanged: start()
dataModel: model
}
}


So, in C++, I added the 2 lines for the data model:


QScxmlStateMachine* machine = new MediaPlayerStateMachine() ;
TheDataModel* dataModel = new TheDataModel();

machine->setDataModel(dataModel);
machine->start();



Hope it helps some of you.

Have great vacation everyone.