Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Solved] Segfault trying to connect QML signal to CPP slot



  • Qt 5.2.1, visual studio 2010.

    In my class constructor I have the following code, and at runtime m_uiRoot is 0 at the Q_CHECK_PTR call.

    Solution: It was a weird QML syntax error

    @m_view = new QQuickView;
    Q_CHECK_PTR(m_view);

    m_view->setSource(QUrl::fromLocalFile("ControlPanel.qml"));
    m_view->show();

    m_uiRoot = m_view->rootObject();
    Q_CHECK_PTR(m_uiRoot); //SEGFAULT HERE

    connect(m_uiRoot, SIGNAL(Scene1Pessed()), this, SLOT(handleButtonClicked()));
    connect(m_uiRoot, SIGNAL(Scene2Pressed()), this, SLOT(handleButtonClicked()));
    connect(m_uiRoot, SIGNAL(Scene3Pressed()), this, SLOT(handleButtonClicked()));
    connect(m_uiRoot, SIGNAL(Scene4Pressed()), this, SLOT(handleButtonClicked()));
    connect(m_uiRoot, SIGNAL(Scene5Pressed()), this, SLOT(handleButtonClicked()));
    connect(m_uiRoot, SIGNAL(Scene6Pressed()), this, SLOT(handleButtonClicked()));
    @


  • Qt Champions 2017

    Quick check - Are you able to see QML window ? Are you able to launch the ControlPanel.qml separately ? What is the top-level item of ControlPanel.qml ? Is it ApplicationWindow or Rectangle ?



  • Rectangle.I've launched the qml window by itself before in a barebones cpp application. m_uiRoot has type QObject *


  • Qt Champions 2017

    what was the issue ? Can post your answer here. It helps others in the forum.


Log in to reply