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

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 27 Jul 2015, 14:49 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

    P 1 Reply Last reply 28 Jul 2015, 14:37
    0
    • A AQTStudent
      27 Jul 2015, 14:49

      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

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 28 Jul 2015, 14:37 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 31 Jul 2015, 19:47 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

        2/3

        28 Jul 2015, 14:37

        • Login

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