QML mousearea not working if QQmlApplication in different class



  • Hello,
    I'm trying to initialize QQmlApplication in a different class
    Main file:

    int main(int argc, char *argv[])    {
        QApplication app(argc, argv);
        //QQmlApplicationEngine engine(QUrl("qrc:/main.qml"));
    
        DigitalClock clockie;
        return app.exec();
    }
    

    DigitalClock file:

    DigitalClock::DigitalClock(QWidget *parent)
        : QWidget(parent)
    {
        QTimer *timer2 = new QTimer(this);
        QObject::connect(timer2, SIGNAL(timeout()), this, SLOT(showTimee()));
        timer2->start(10000);
    
        QQmlApplicationEngine engine(QUrl("qrc:/main.qml"));
    
        QQmlComponent component(&engine, QUrl("qrc:/main.qml"));
        QObject *object = component.create();
        timee = object->findChild<QObject*>("clockOnTop");
        qDebug() << component.errors();
    
    }
    

    Now my problem.
    If I initialize the QQmlApplicationEngine in the DigitalClock file, no mouse events are working..
    If I initiliaze the QQmlApplicationEngine in the main file, the mouse events are working.. however I'm having trouble editing parts of the qml file later, which I do in the digitalclock file..

    Can anyone give me any advise?

    Kind regards,
    Jorrick Sleijster


  • Moderators

    Hi @AQTStudent
    First what is your aim in adding QQmlApplicationEngine in QWidget ? Do you want to embed the QML in QWidget ?
    Also why are you loading main.qml twice ?



  • I still had to remove the QWidget.. it's useless this way.
    My error was that I can't have a QWidget class without a QQmlApplicationEngine.



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