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. Setting context property for a QQuickView crashing? [SOLVED]
Forum Updated to NodeBB v4.3 + New Features

Setting context property for a QQuickView crashing? [SOLVED]

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.8k Views 1 Watching
  • 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.
  • E Offline
    E Offline
    EStudley
    wrote on last edited by
    #1

    Hey there. So I'm having a problem accessing the functions from a class that inherits QObject in my QMainWindow. Here's the initializer for my MainWindow:

    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    QQuickView *view = new QQuickView;
    cryptsyAPI cryptsyInterface;
    view->engine()->rootContext()->setContextProperty("Cryptsy", &cryptsyInterface);
    view->setFlags(Qt::Dialog);
    view->setSource(QUrl("qml/Bit-sy/main.qml"));
    

    }@

    cryptsyAPI is a class that inherits QObject. Here's the .h file:

    @class cryptsyAPI : public QObject
    {
    Q_OBJECT

    public:
    explicit cryptsyAPI(QObject *parent = 0);
    ~cryptsyAPI();

    public slots:
    void timedAPIRefresh();
    };@

    "TimedAPIRefresh" right now only outputs "Hello" to the console with qDebug().
    Everything works and compiles perfectly fine, but when I try to access the function from QML, like so:

    @ onClicked:{
    Cryptsy.timedAPIRefresh();
    }@

    The program crashes. Any idea why? When I open the crash report in Visual Studio, it says "Unhandled exception at 0x000000006D100432 (Qt5Qml.dll) in Bit-sy.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF."

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Just an educated guess but cryptsyInterface is destroyed at the end of the constructor so accessing it should trigger the crash.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • E Offline
        E Offline
        EStudley
        wrote on last edited by
        #3

        Thank you so much! I had been working on that for several hours when I posted this, I wasn't thinking clearly!

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You're welcome !

          If this solves your problem, then please update the thread title prepending [solved] so other forum users may know a solution has been found :)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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