Results 1 to 4 of 4

Thread: Program works normally but QML Reference Error

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2019
    Posts
    12
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Program works normally but QML Reference Error

    I have it on my main file:

    Qt Code:
    1. #include <QGuiApplication>
    2. #include <QQmlApplicationEngine>
    3. #include <QDebug>
    4. #include <keppoxd.h>
    5. #include <siema.h>
    6. #include <QQmlContext>
    7. #include <QQmlApplicationEngine>
    8.  
    9. int main(int argc, char *argv[])
    10. {
    11.  
    12. QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    13.  
    14. QGuiApplication app(argc, argv);
    15.  
    16.  
    17.  
    18. siema siema;
    19. keppoxd keppo;
    20.  
    21. keppo.siema = &siema;
    22.  
    23. QQmlApplicationEngine engine;
    24. const QUrl url(QStringLiteral("qrc:/main.qml"));
    25. QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
    26. &app, [url](QObject *obj, const QUrl &objUrl) {
    27. if (!obj && url == objUrl)
    28. QCoreApplication::exit(-1);
    29. }, Qt::QueuedConnection);
    30. engine.load(url);
    31.  
    32.  
    33. QQmlContext *ctx = engine.rootContext();
    34.  
    35. ctx->setContextProperty("Siemaqml", &siema);
    36. ctx->setContextProperty("Keppoqml", &keppo); // HERE
    37.  
    38. return app.exec();
    39. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,329
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Program works normally but QML Reference Error

    Your code is loading the QML before it calls setContextProperty(). Read anda_skoa's reply again.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. error: undefined reference to. Where?
    By remizero in forum Installation and Deployment
    Replies: 4
    Last Post: 8th April 2017, 18:06
  2. Replies: 1
    Last Post: 23rd April 2014, 10:03
  3. Replies: 4
    Last Post: 27th August 2013, 15:34
  4. Replies: 5
    Last Post: 16th December 2010, 10:12
  5. Program works in Release but not Debug
    By Ferric in forum Newbie
    Replies: 2
    Last Post: 28th January 2010, 01:08

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
  •  
Qt is a trademark of The Qt Company.