Results 1 to 4 of 4

Thread: ApplicationWindow as root object result in error

  1. #1
    Join Date
    Apr 2009
    Posts
    206
    Thanks
    34
    Thanked 2 Times in 2 Posts

    Default ApplicationWindow as root object result in error

    Hello friends,

    I have expose one c++ classes to qml in a main.cpp file like this:

    Qt Code:
    1. int main(int argc, char** argv)
    2. {
    3. QGuiApplication app(argc, argv);
    4.  
    5.  
    6. qmlRegisterType<MyTestClass>("Test", 1, 0, "Test");
    7.  
    8.  
    9. QQuickView view;
    10. view.resize(800, 480);
    11. view.setResizeMode(QQuickView::SizeRootObjectToView);
    12. view.setSource(QUrl("qrc:///main.qml"));
    13. view.show();
    14. return app.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

    But my root object in qml is a ApplicationWindow object. So I get a
    QQuickView only supports loading of root objects that derive from QQuickItem.
    So when I avoid the main.cpp I have to run the qml file with qmlscene. But I want to have an exe file. How can I use an main.cpp in combinatiion with a ApplicationWindow root object in a qml file?

    Yours,

  2. #2
    Join Date
    Aug 2011
    Posts
    7
    Thanked 1 Time in 1 Post

    Default Re: ApplicationWindow as root object result in error

    The error message is correct. ApplicationWindow is a QQuickWindow and not a QQuickItem. QQuickView is also a window which causes the problem. (you are creating a window in C++ that essentially is supposed to create another window declared in Qt Quick. If this is targetting Qt 5.1 there is a new QQmlApplicationEngine you can use for exactly this purpose. Alternatively is that you create a QQmlEngine yourself instead of a QQuickView to launch your qml file.

    http://doc-snapshot.qt-project.org/q...ionengine.html

  3. #3
    Join Date
    Dec 2013
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: ApplicationWindow as root object result in error

    hello,
    i had the same problem with Quickview but when i switched into QQmlApplicationEngine and then run the application nothing happens , i mean no gui is loaded only the application process is launched and no error is availble , any ideas plz ?
    main.cpp :
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    QQmlApplicationEngine engin(QUrl("qrc:/main.qml"));
    return app.exec();
    }

  4. #4
    Join Date
    Feb 2014
    Posts
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X

    Lightbulb Re: ApplicationWindow as root object result in error

    You are correct that QQmlApplicationEngine should be used. Just note that it doesn't show() the window, so you should explicitly set the visibility on the ApplicationWindow to true;

  5. The following user says thank you to Itehnological for this useful post:

    codeman (25th February 2014)

Similar Threads

  1. Replies: 0
    Last Post: 28th May 2012, 20:56
  2. Replies: 0
    Last Post: 9th August 2011, 11:15
  3. Replies: 2
    Last Post: 7th July 2009, 18:44
  4. Replies: 2
    Last Post: 8th October 2007, 16:02
  5. Error declaring Qt object
    By Doug Broadwell in forum Qt Programming
    Replies: 3
    Last Post: 9th September 2007, 22:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.