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. How to get window handle while I use QML?

How to get window handle while I use QML?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 3.2k 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.
  • S Offline
    S Offline
    Soul
    wrote on last edited by aha_1980
    #1

    The initialization code is below:

    int main(int argc, char *argv[])
    {
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
        QGuiApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        engine.load(QUrl(QLatin1String("qrc:/main.qml")));
        if (engine.rootObjects().isEmpty())
            return -1;
    
        return app.exec();
    }
    

    where I can get the HANDLE of th "main.qml" ?

    A champion is someone who gets up even when he can´t.

    raven-worxR 1 Reply Last reply
    0
    • S Soul

      The initialization code is below:

      int main(int argc, char *argv[])
      {
          QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
          QGuiApplication app(argc, argv);
      
          QQmlApplicationEngine engine;
          engine.load(QUrl(QLatin1String("qrc:/main.qml")));
          if (engine.rootObjects().isEmpty())
              return -1;
      
          return app.exec();
      }
      

      where I can get the HANDLE of th "main.qml" ?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @Soul

      if( QQuickWindow* window = qobject_cast<QWindow*>( engine.rootObjects().at(0) ) )
           window->winId();
      

      (untested)

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3
      • S Offline
        S Offline
        Soul
        wrote on last edited by
        #3

        @raven-worx Thank you reaven

        A champion is someone who gets up even when he can´t.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Soul
          wrote on last edited by
          #4

          May be we should replace "QQuickWindow" as "QWindow"

          A champion is someone who gets up even when he can´t.

          raven-worxR 1 Reply Last reply
          0
          • S Soul

            May be we should replace "QQuickWindow" as "QWindow"

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            @Soul
            yes this is a typo .. and wouldn't compile anyway.
            my first intention was to use QWindow, since i also did the corresponding cast.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            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