Results 1 to 5 of 5

Thread: component->loadUrl throws error

  1. #1
    Join Date
    Dec 2015
    Location
    Austria
    Posts
    23
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows Android

    Default component->loadUrl throws error

    I want to create a QML Comonent on runtime.
    I found some samples and i tried it, but i am not always getting an abortion when laoding the URL into the component.
    I tried several URLs to be sure i got a working one but i always get the abortion (read acces Violation) which i thought is a Problem when getting the qml file.

    Qt Code:
    1. QQmlComponent *component = new QQmlComponent(viewController.getAppEngine().data());
    2. //component->loadUrl(QUrl("qrc:///qml/components/LabelStringEdit.qml")); // ABORTION IS HERE!!! This line should work in my opinion...
    3. //component->loadUrl(QUrl("qrc:/qml/components/LabelStringEdit.qml"));// ABORTION IS HERE!!!
    4. //component->loadUrl(QUrl("qrc:module/settings/view_settings_connector_sageX3.qml"));// ABORTION IS HERE!!!
    5. component->loadUrl(QUrl::fromLocalFile("C:/Development/QtTest/qml/components/LabelStringEdit.qml")); // ABORTION IS HERE!!!
    6. QQuickItem *quickItem = qobject_cast<QQuickItem*>(component->create());
    7. QQuickItem *parentQuickItem = qobject_cast<QQuickItem*>(_rootObject);
    8. QQmlEngine::setObjectOwnership(quickItem, QQmlEngine::CppOwnership);
    9. quickItem->setParent(this);
    10. quickItem->setVisible(true);
    11. quickItem->setParentItem(parentQuickItem);
    To copy to clipboard, switch view to plain text mode 

    Is there anything i am doeing wrong?
    The QML is a Quck QML file...

    Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: component->loadUrl throws error

    Well, what do the errors say?
    Can you load the file in qmlscene?

    Cheers,
    _

  3. #3
    Join Date
    Dec 2015
    Location
    Austria
    Posts
    23
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows Android

    Default Re: component->loadUrl throws error

    I tried it to load in a loader and all samples below work!

    Qt Code:
    1. Loader {
    2. width: 500;
    3. height: 500;
    4. source: "qrc:///qml/components/LabelStringEdit.qml";
    5. }
    6.  
    7. Loader {
    8. width: 500;
    9. height: 500;
    10. source: "qrc:/qml/components/LabelStringEdit.qml";
    11. }
    To copy to clipboard, switch view to plain text mode 

    The error i get:
    Debug Error
    File: global\qglobal.cpp
    Line: 2966
    ASSERT: "e" in file ...qqmlengine_p.h line 378

    With the QMLSCENE it does not work because i do have an Import in my LabelStringEdit.qml
    Qt Code:
    1. import "qrc:/qml/components" as Controls
    To copy to clipboard, switch view to plain text mode 
    ans of course qmlscene cant find "qrc:/qml/components" but my app should find?! Do i have to provide the Import path to the "QQmlComponent" class?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: component->loadUrl throws error

    Quote Originally Posted by ChriD View Post
    I tried it to load in a loader and all samples below work!
    Good to know.
    The URIs looked fine already,

    Quote Originally Posted by ChriD View Post
    The error i get:
    I was more thinking along the lines of the errors reported by QQmlComponent::errors(), but you are hitting an assert.
    Are you sure that viewController.getAppEngine().data() is a valid QQmlEngine pointer?

    Cheers,
    _

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

    ChriD (1st February 2016)

  6. #5
    Join Date
    Dec 2015
    Location
    Austria
    Posts
    23
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows Android

    Default Re: component->loadUrl throws error

    Well,

    It was a similar nasty mistake :-)

    The viewController is the parent object of the view class and i used the wrong cast
    Qt Code:
    1. View::ViewController viewController = qobject_cast<View::ViewController>(this->parent()); // of course wrong because parent() returns a pointer
    2. View::ViewController *viewController = qobject_cast<View::ViewController*>(this->parent()); // this is correct...
    To copy to clipboard, switch view to plain text mode 
    In fact there was no Compiler error and the Controller and the engine object was filled, but pointed anywhere in the memory
    It works now!


    Thank You!

Similar Threads

  1. Qt 5 QSystemTrayIcon throws error message on Mac OS X
    By janusz in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2013, 14:55
  2. Replies: 3
    Last Post: 5th May 2012, 05:03
  3. Replies: 7
    Last Post: 3rd December 2010, 05:02
  4. py2app-deployed PyQt app -- throws QObject threading error
    By tory108 in forum Installation and Deployment
    Replies: 4
    Last Post: 20th January 2009, 20:16
  5. QThread + QTimer + skype4Com throws exception
    By sadjoker in forum Newbie
    Replies: 1
    Last Post: 22nd December 2008, 14:24

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.