qml qt freeze at the time of cpp funtion call



  • my test application get freeze when i call cpp function, as function finishes everything work fine,, i need to call same cpp function repeatedly.

    sm20.h

    #ifndef SM20_H
    #define SM20_H

    #include <QObject>
    #include <QDateTime>
    #include <QFile>
    #include <QtGui>
    #include <QtCore>
    #include <QTimer>

    class SM20: public QThread
    {
    Q_OBJECT
    public :
    void set_up();
    public slots :
    void testSm20();
    };
    #endif // SM20_H

    main.cpp

    #include "qtquick1applicationviewer.h"
    #include <QApplication>
    #include "sm20.h"
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QtQuick1ApplicationViewer viewer;
    viewer.addImportPath(QLatin1String("modules"));
    viewer.setOrientation(QtQuick1ApplicationViewer::ScreenOrientationAuto);
    viewer.setMainQmlFile(QLatin1String("qrc:/main.qml"));
    viewer.showExpanded();

    SM20 sm20;
    //sm20.testSm20();
    

    QObject *object = viewer.rootObject();
    QObject::connect(object, SIGNAL(mySignal()), &sm20, SLOT(testSm20()));
    return app.exec();
    }

    sm20.cpp

    #include <QApplication>
    #include <QTimer>
    #include "FP.h"
    #include "sm20.h"

    void SM20 :: set_up()
    {
    setUp();
    }

    void SM20 :: testSm20()
    {
    setUp();
    qDebug () << "inside test\n";
    ledOn();
    ledOff();
    ledOn();
    ledOff();
    }

    main.qml

    import QtQuick 1.1

    Rectangle {
    width: 480
    height: 270
    signal mySignal()
    Item {
    Timer {
    interval: 10000; running: true; repeat: true
    onTriggered: mySignal()
    }
    }
    }



  • my program freeze at the time of testSm20().
    help me to rid of this issue.


  • Moderators

    First question: why does SM20 inherit from QThread?
    You don't implement void run() method.
    Are you trying to execute void testSm20() in a separate thread? If so then you're doing it wrong.

    What does setUp() do?
    What is in ledOn()?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.