Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML mousearea not working if QQmlApplication in different class
QtWS25 Last Chance

QML mousearea not working if QQmlApplication in different class

Scheduled Pinned Locked Moved QML and Qt Quick
qqmlapplicationmouseareaqmlc++initialize
3 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AQTStudent
    wrote on last edited by
    #1

    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

    p3c0P 1 Reply Last reply
    0
    • A AQTStudent

      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

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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 ?

      157

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AQTStudent
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved