Results 1 to 2 of 2

Thread: SCXML and QScxmlCppDataModel cause a segmentation fault

  1. #1
    Join Date
    Oct 2012
    Location
    France
    Posts
    29
    Thanks
    1
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default SCXML and QScxmlCppDataModel cause a segmentation fault

    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:

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QCoreApplication a(argc, argv);
    4. QScxmlStateMachine* machine = new MediaPlayerStateMachine() ;
    5.  
    6. machine->start();
    7.  
    8. return a.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    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.

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QGuiApplication app(argc, argv);
    4.  
    5. qmlRegisterType<TheDataModel>("MediaPlayerDataModel", 1, 0, "MediaPlayerDataModel");
    6. qmlRegisterType<MediaPlayerStateMachine>("MediaPlayerStateMachine", 1, 0, "MediaPlayerStateMachine");
    7.  
    8. QQmlApplicationEngine engine;
    9. engine.load(QUrl(QStringLiteral("qrc:///mediaplayer-qml-cppdatamodel.qml")));
    10.  
    11. QScxmlStateMachine* machine = new MediaPlayerStateMachine() ;
    12. machine->start();
    13.  
    14. return app.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 


    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

  2. #2
    Join Date
    Oct 2012
    Location
    France
    Posts
    29
    Thanks
    1
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: SCXML and QScxmlCppDataModel cause a segmentation fault

    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.

Similar Threads

  1. segmentation fault
    By lawrence Anthony in forum Newbie
    Replies: 1
    Last Post: 30th November 2011, 21:58
  2. Segmentation Fault
    By freekill in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2010, 15:31
  3. segmentation fault
    By dreamer in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2008, 07:48
  4. Segmentation Fault?!
    By r07f1 in forum Newbie
    Replies: 2
    Last Post: 11th April 2008, 15:10
  5. Segmentation Fault
    By merry in forum General Programming
    Replies: 4
    Last Post: 12th March 2007, 04:08

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.