-1

I just started out with Qt. I've written a little QML-Button, and there's a problem which drives me crazy. I just can't get it to work.

// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1

Item {
id: bluebutton
property alias labeltext: label.text
signal pressed()

width: 130
height: 40
    Rectangle {
        id: rect
        anchors.fill: parent
        color: "darkblue"
        Text {
            id: label
            scale: 2
            color: "white"
            anchors.centerIn: parent
        }
        MouseArea {
            id: mousefield
            anchors.fill: parent
            onClicked: bluebutton.pressed() //.pressed() doesn't appear in the suggestions
        }
    }
}

So here's the problem:
apparently, i cant refer to any kind of signal defined in the Item-Element. I tried to refer to the property "labeltext" (bluebutton.labeltext) and it worked. But i can't refer to pressed() ! Why? Needless to say, the Button doesn't work...

Rectangle {
    width: 250
    height: 200
    color: "lightblue"

    Button {
        labeltext: "Quit"
        onPressed: Qt.quit
    }
}

Does anybody know whats going on?


EDIT: Ok, signals do work... -.- But Qt.quit doesn't work for some reason...

1 Answer 1

1

I finally found the solution:
I forgot braces...

wrong: Qt.quit
right: Qt.quit()

There you go. Conclusion: Always check if you forgot braces =D

1
  • 2
    The appöication output in QtCreator is quiet useful for debugging stuff like this. Normally you can find there some error message.
    – KimKulling
    Aug 22, 2014 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.