0

I have a c++ class that inherited from QObject with name LoginManager (that I registerd this with qmlRegisterTypes) in main.qml file

LoginManager{
    id: loginManager
}

now I want to add a LoginPage.qml file to a StackView

sv.push("/pages/LoginPage.qml",{lManager:loginManager});

LoginPage

Page {
    id: root
    property LoginManager lManager

    Connections{
        target: lManager

        onMessageChanged: {
        }
        onLoginSuccessed: {
        }
    }
}

but I have and error when click button to add LoginPage.qml to StackView

QmlComponent: Component is not ready qrc:/main.qml:395:5: QML StackView: push: qrc:/pages/LoginPage.qml:16 Cannot assign object to property

I have done same work on another pages but I don't know why I got error just here?

Edit

when I comment the Connections ,the error will go!

mohsen
  • 1,763
  • 3
  • 17
  • 55
  • LoginManager is a QQuickItem or a QObject? – eyllanesc Apr 23 '18 at 17:11
  • @eyllanesc It is a c++ class that inherited from QObject – mohsen Apr 23 '18 at 17:51
  • 3
    push requires an Item, which in C ++ is equivalent to QQuickItem, if LoginManager is unique I would recommend creating it in C ++ and using setContextProperty() to export it to QML and you can access that object in any part of your application. – eyllanesc Apr 23 '18 at 17:53

1 Answers1

-2

You used an absolute URL to point to your login page component. Try to make it relative:

sv.push("./pages/LoginPage.qml",{lManager:loginManager});

That should do the trick.

Martin Höher
  • 715
  • 5
  • 9
  • Hm... this is strange. I reproduced your problem locally (in pure QML) and using the absolute path was what actually caused the `Component is not ready` message to be printed. Maybe you could try to change the property from `property LoginManager lManager` to be `property var lManager`; sometimes I had trouble with "typed" properties in the past as well, but I cannot say for sure if this will solve your issue... – Martin Höher Apr 26 '18 at 07:10