0

In an QML-Application I instantiate two classes that inherit QObject and one class needs access to the other class. Also both classes are declared to qml in main.cpp by qmlRegisterType. When I use code like the following I get an qqmlprivate-error. This question is similar to this but it's not the same. How can I fix this? Thank you!

TimeControl.h

class TimeControl : public QObject
{
    Q_OBJECT
public:
    explicit TimeControl(QObject *parent = nullptr);
};

MyTimeTable.h

class MyTimeTable : public QObject
{
    Q_OBJECT
public:
    explicit MyTimeTable(TimeControl *timeControl, QObject *parent = nullptr);
private:
    TimeControl *m_timeControl = nullptr;
};

MyTimeTable.cpp

MyTimeTable::MyTimeTable(TimeControl *timeControl, QObject *parent)
    : QObject(parent)
{
    m_timeControl = timeControl;
}

main.cpp

qmlRegisterType<TimeControl>  ("tld.we.TimeControl", 1, 0, "TimeControl");
qmlRegisterType<MyTimeControl>  ("tld.we.MyTimeTable", 1, 0, "MyTimeTable");
TimeControl *timeControl = new TimeControl();
MyTimeTable timeTable(timeControl);

added QML-Code

import tld.we.MyTimeTable 1.0

Popup{
MyTimeTable{
    id: timeTable
}

ToolButton{
    text: "Update"
    onClicked:
        timeTable.updateData();
}
Klara Fall
  • 11
  • 4
  • Seems like this is a bug: `MyTimeTable timeTable(&timeControl);` Should probably be `MyTimeTable timeTable(timeControl);`? Also, please add the error message you are receiving and any QML you have written to try and access these objects/classes. – David K. Hess May 06 '20 at 13:34
  • Yes, that's a bug. The error messages result from qqmlprivate.h: no matching function for call to 'MyTimeTable::MyTimeTable()' and use of deleted function 'QQmlPrivate::QQmlElement::QQmlElement()' Thanks! – Klara Fall May 06 '20 at 13:47
  • Are those runtime errors from QML or compile time errors? If from QML, please add your QML code to your question. – David K. Hess May 06 '20 at 13:50
  • If you are going to use qmlRegisterType with MyTimeTable it implies that you are going to create that object in QML so the constructor is not necessarily going to receive TimeControl and that is detected when compiling. – eyllanesc May 06 '20 at 14:03
  • A possible solution is to implement the timeControl in MyTimeTable as a Q_PROPERTY. – eyllanesc May 06 '20 at 14:07

0 Answers0