create a state



  • Hi, I just make a file with a simple state, but I don't know why doesn't works..
    the code:

    import QtQuick 2.2
    import QtQuick.Controls.Styles 1.2
    
    Item {
        Rectangle {
            id: top
            color: "blue"
            width : 200
            height: 200
    
            Component.onCompleted: state = "menu"
            Rectangle
            {
                id: inicio
                color: "red"
                anchors.fill: parent
                opacity: 1
    
                Button {
                    id: blue
                    anchors.horizontalCenter: parent.horizontalCenter
                    anchors.verticalCenter: parent.verticalCenter
                    label: "ligar"
                    onButtonClick: {top.state = "begin";}
                }
            }
            Rectangle {
                id: segundo
                opacity: 0
                anchors.centerIn: top
                color: "#f11717"
                anchors.fill: parent
    
            }
        }
    
        states: [
    
            State {
                name: "menu"
                PropertyChanges { target: inicio; opacity: 1 }
                PropertyChanges { target: segundo; opacity: 0 }
            },
            State {
                name: "begin"; when: Button.clicked = true
                PropertyChanges { target: inicio; opacity: 0 }
                PropertyChanges { target: segundo; opacity: 1 }
            }
        ]
    }
    

    I need to write something in the other files? like .pro or .cpp? it's compile, but when I transfer for my mobile the screen is always black. And appears this message: 'showStatusIcon on inactive InputConnection.'

    Thanks a lot.

    Edited: Please follow Markdown syntax rules - p3c0


  • Moderators

    @joanaguimas Which Project did you choose in QtCreator ? Qt Quick Application or Qt Quick UI ?



  • This post is deleted!


  • @p3c0 I choose Qt Quick Application.


  • Moderators

    @joanaguimas Ok. Are you sure it runs on your development machine ? I see a few issues here like label and onButtonClick. There's no such property nor the event handler.



  • @p3c0
    I have a Button.qml which code is:

    import QtQuick 2.0
    
    Rectangle {
        // Identifier of the item
        id: button
    
        // Attaches to the Text element's text content
        property string label
    
        // Set appearance properties
        radius: 3
        antialiasing: true
        border.width: 1
        border.color: "#35322f"
        color: "#14aaff"
        height: buttonLabel.height * 1.5
        width: buttonLabel.width * 1.5
    
        Text {
            id: buttonLabel
            anchors.centerIn: parent
            text: label     // Bind the text to the parent's text
            color: "black"
            font.pointSize: 20
        }
    
        // buttonClick() is callable and a signal handler,
        // onButtonClick is automatically created
        signal buttonClick()
    
        // Define the clickable area to be the whole rectangle
        MouseArea {
            id: buttonMouseArea
            anchors.fill: parent    // Stretch the area to the parent's dimension
            onClicked: buttonClick()
        }
    
        // Scale the button when pressed
        scale: buttonMouseArea.pressed ? 1.1 : 1.0
        // Animate the scale property change
        Behavior on scale { NumberAnimation { duration: 55 } }
    }
    
    

    I just used this and it works fine.. this is only an example for create state, because I just tried more examples, but without sucess and I don't know why..


  • Moderators

    @joanaguimas Did you try very basic example ? like "hello world" for QML ?
    Apart from that which OS are you targeting and which Qt version ?



  • @p3c0 yes, I tried. I even made ​​an application with connection to bluetooth and it works well in my mobile. The problem is I can't create a simple state, maybe is the code, or something else that I need to do and I didn't.

    I have Qt 5.3.2, and the other question I dont't understood what it is..


  • Moderators

    @joanaguimas Sorry, I meant the mobile platform i.e Android (Linux) or Windows. Can you explain what you are trying to achieve ? I ran your example but I'm not understanding what you are trying to do. Also I would avoid keeping the name as Button.qml as QML already consists a component named Button and it may conflict.



  • @p3c0 It is for android . I'm trying to create an application . I have a home page with the button 'In'. I've tried using the Loader page to change the page by pressing the button 'In', but takes a long time and sometimes does not work , and now I'm trying to do through states to see if it works better .. but I can't.

    for example I tried this code, without Button et all..

    import QtQuick 2.2
    
    
    Rectangle
    {
    
        id: main
        color: "blue"
        width : 200
        height: 200
    
    Rectangle
    {
        id: login
        color: "red"
        anchors.fill: parent
        opacity: 1
    }
    
    Rectangle {
        id: menu
        color: "green"
        anchors.fill: parent
        opacity: 0
    }
    
    
    MouseArea
    {
     anchors.fill: parent
     onClicked: parent.state = "begin"
    }
    
    
    states: [State {
            name:"begin"
            PropertyChanges { target: login; opacity: 0 }
            PropertyChanges { target: menu; opacity: 1 }
        }]
    
    }
    

    It is very simple, it just change de color
    And the result it is the same..


  • Moderators

    @joanaguimas Well this works! But are you sure it doesn’t work due to State ?



  • @p3c0 I don't know.. the other applications that I made, without states works well.. Have you any idea what the problem is?



  • @p3c0 I got this when I run the application:

    Starting remote process.D/dalvikvm( 1362): Late-enabling CheckJNI
    D/dalvikvm( 1362): GC_CONCURRENT freed 326K, 12% free 9573K/10823K, paused 2ms+33ms, total 101ms
    D/dalvikvm( 1362): WAIT_FOR_CONCURRENT_GC blocked 88ms
    D/dalvikvm( 1362): GC_CONCURRENT freed 496K, 13% free 9594K/11015K, paused 32ms+2ms, total 185ms
    D/dalvikvm( 1362): WAIT_FOR_CONCURRENT_GC blocked 94ms
    D/dalvikvm( 1362): Trying to load lib /data/data/org.qtproject.example.untitled4/lib/libgnustl_shared.so 0x4191e608
    D/dalvikvm( 1362): Added shared lib /data/data/org.qtproject.example.untitled4/lib/libgnustl_shared.so 0x4191e608
    D/dalvikvm( 1362): No JNI_OnLoad found in /data/data/org.qtproject.example.untitled4/lib/libgnustl_shared.so 0x4191e608, skipping init
    D/dalvikvm( 1362): Trying to load lib /data/data/org.qtproject.example.untitled4/lib/libQt5Core.so 0x4191e608
    D/dalvikvm( 1362): Added shared lib /data/data/org.qtproject.example.untitled4/lib/libQt5Core.so 0x4191e608
    D/dalvikvm( 1362): Trying to load lib /data/data/org.qtproject.example.untitled4/lib/libQt5Network.so 0x4191e608
    D/dalvikvm( 1362): Added shared lib /data/data/org.qtproject.example.untitled4/lib/libQt5Network.so 0x4191e608
    D/dalvikvm( 1362): No JNI_OnLoad found in /data/data/org.qtproject.example.untitled4/lib/libQt5Network.so 0x4191e608, skipping init
    D/dalvikvm( 1362): Trying to load lib /data/data/org.qtproject.example.untitled4/lib/libQt5Qml.so 0x4191e608
    D/dalvikvm( 1362): Added shared lib /data/data/org.qtproject.example.untitled4/lib/libQt5Qml.so 0x4191e608
    D/dalvikvm( 1362): No JNI_OnLoad found in /data/data/org.qtproject.example.untitled4/lib/libQt5Qml.so 0x4191e608, skipping init
    D/dalvikvm( 1362): Trying to load lib /data/data/org.qtproject.example.untitled4/lib/libQt5Gui.so 0x4191e608
    D/dalvikvm( 1362): Added shared lib /data/data/org.qtproject.example.untitled4/lib/libQt5Gui.so 0x4191e608
    D/dalvikvm( 1362): No JNI_OnLoad found in /data/data/org.qtproject.example.untitled4/lib/libQt5Gui.so 0x4191e608, skipping init
    D/dalvikvm( 1362): Trying to load lib /data/data/org.qtproject.example.untitled4/lib/libQt5Quick.so 0x4191e608
    D/dalvikvm( 1362): Added shared lib /data/data/org.qtproject.example.untitled4/lib/libQt5Quick.so 0x4191e608
    D/dalvikvm( 1362): No JNI_OnLoad found in /data/data/org.qtproject.example.untitled4/lib/libQt5Quick.so 0x4191e608, skipping init
    D/dalvikvm( 1362): Trying to load lib /data/data/org.qtproject.example.untitled4/lib/libQt5QuickParticles.so 0x4191e608
    D/dalvikvm( 1362): Added shared lib /data/data/org.qtproject.example.untitled4/lib/libQt5QuickParticles.so 0x4191e608
    D/dalvikvm( 1362): No JNI_OnLoad found in /data/data/org.qtproject.example.untitled4/lib/libQt5QuickParticles.so 0x4191e608, skipping init
    D/dalvikvm( 1362): Trying to load lib /data/data/org.qtproject.example.untitled4/qt-reserved-files/plugins/platforms/android/libqtforandroid.so 0x4191e608
    D/dalvikvm( 1362): Added shared lib /data/data/org.qtproject.example.untitled4/qt-reserved-files/plugins/platforms/android/libqtforandroid.so 0x4191e608
    I/Qt ( 1362): qt start
    D/dalvikvm( 1362): Trying to load lib /data/data/org.qtproject.example.untitled4/lib/libQt5QuickParticles.so 0x4191e608
    D/dalvikvm( 1362): Shared lib '/data/data/org.qtproject.example.untitled4/lib/libQt5QuickParticles.so' already loaded in same CL 0x4191e608
    D/dalvikvm( 1362): Trying to load lib /data/data/org.qtproject.example.untitled4/lib/libuntitled4.so 0x4191e608
    D/dalvikvm( 1362): Added shared lib /data/data/org.qtproject.example.untitled4/lib/libuntitled4.so 0x4191e608
    D/dalvikvm( 1362): No JNI_OnLoad found in /data/data/org.qtproject.example.untitled4/lib/libuntitled4.so 0x4191e608, skipping init
    D/libEGL ( 1362): loaded /system/lib/egl/libGLES_hawaii.so
    D/ ( 1362): mem_init ++
    D/ ( 1362): gHwMemAllocator client 3
    D/ ( 1362): **** Using ION allocator ****
    D/ ( 1362): registered SIGUSR1[10] for pid[1362]
    D/ ( 1362): HwMemAllocatorImpl Static Counters 0 0
    D/ ( 1362): HwMemAllocatorImpl[4d9e1d5c] totalDeviceAllocSize[0] totalFree[0] maxFree[0] in numSlabs[0]
    D/ ( 1362): mem_init 4d9e1d5c--
    D/ION ( 1362): config: version(0x10000) secure(0xf000) 256M(0x22d) fast(0x608) hwwr(0x608)
    D/ ( 1362): Waiting for mm thread to come up
    D/ ( 1362): mm_device_thread starting
    D/HAWAII_EGL( 1362): eglCreateContext() config: 35 context: 0x4fbf92a0, VC context 1, Thread 1362
    D/HAWAII_EGL( 1362): Set SWAP INTERVAL 0
    D/HAWAII_EGL( 1362): eglCreateWindowSurface() surface: 0x4fbf9318, VC surface: 1, Thread: 1362
    D/HAWAII_EGL( 1362): eglMakeCurrent(0x4fbf92a0, 0x4fbf9318, 0x4fbf9318) Thread: 1362
    D/OpenGLRenderer( 1362): Enabling debug mode 0
    D/HAWAII_EGL( 1362): eglMakeCurrent(0x4fbf92a0, 0x51e64340, 0x51e64340) Thread: 1362
    D/HAWAII_EGL( 1362): eglMakeCurrent(NULL) Thread: 1362
    D/HAWAII_EGL( 1362): eglMakeCurrent(0x4fbf92a0, 0x51e64340, 0x51e64340) Thread: 1362
    D/HAWAII_EGL( 1362): eglMakeCurrent(NULL) Thread: 1362
    D/HAWAII_EGL( 1362): eglMakeCurrent(0x4fbf92a0, 0x51e64340, 0x51e64340) Thread: 1362
    D/HAWAII_EGL( 1362): eglMakeCurrent(NULL) Thread: 1362
    D/HAWAII_EGL( 1362): eglMakeCurrent(0x4fbf92a0, 0x51e64340, 0x51e64340) Thread: 1362
    D/HAWAII_EGL( 1362): eglMakeCurrent(NULL) Thread: 1362
    D/HAWAII_EGL( 1362): eglMakeCurrent(0x4fbf92a0, 0x51e64340, 0x51e64340) Thread: 1362
    D/HAWAII_EGL( 1362): eglMakeCurrent(NULL) Thread: 1362
    D/dalvikvm( 1362): GC_CONCURRENT freed 377K, 13% free 9658K/11079K, paused 42ms+23ms, total 135ms
    W/IInputConnectionWrapper( 1362): getSelectedText on inactive InputConnection
    W/IInputConnectionWrapper( 1362): setComposingText on inactive InputConnection
    D/HAWAII_EGL( 1362): eglMakeCurrent(0x4fbf92a0, 0x51e64340, 0x51e64340) Thread: 1362
    D/HAWAII_EGL( 1362): eglMakeCurrent(NULL) Thread: 1362
    W/IInputConnectionWrapper( 1362): showStatusIcon on inactive InputConnection
    D/HAWAII_EGL( 1362): eglMakeCurrent(0x4fbf92a0, 0x4fbf9318, 0x4fbf9318) Thread: 1362
    E/SpannableStringBuilder( 1362): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
    E/SpannableStringBuilder( 1362): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
    D/dalvikvm( 1362): WAIT_FOR_CONCURRENT_GC blocked 0ms
    D/dalvikvm( 1362): GC_EXPLICIT freed 94K, 13% free 9640K/11079K, paused 2ms+2ms, total 25ms
    W/IInputConnectionWrapper( 1362): getSelectedText on inactive InputConnection
    W/IInputConnectionWrapper( 1362): setComposingText on inactive InputConnection
    D/HAWAII_EGL( 1362): eglMakeCurrent(NULL) Thread: 1362
    D/HAWAII_EGL( 1362): eglDestroySurface() surface: 0x4fbf9318, android window 0x4dafea20, Thread: 1362
    D/HAWAII_EGL( 1362): eglMakeCurrent(0x4fbf92a0, 0x51e64340, 0x51e64340) Thread: 1362
    D/HAWAII_EGL( 1362): eglMakeCurrent(NULL) Thread: 1362
    D/HAWAII_EGL( 1362): eglMakeCurrent(0x4fbf92a0, 0x51e64340, 0x51e64340) Thread: 1362
    D/HAWAII_EGL( 1362): eglMakeCurrent(NULL) Thread: 1362
    D/HAWAII_EGL( 1362): eglMakeCurrent(0x4fbf92a0, 0x51e64340, 0x51e64340) Thread: 1362
    D/HAWAII_EGL( 1362): eglDestroyContext() context: 0x4fbf92a0, VC context: 1, Thread 1362
    E/HAWAII_EGL( 1362): Destroying surface without window
    D/HAWAII_EGL( 1362): Destroying context in eglMakeCurrent
    D/HAWAII_EGL( 1362): eglMakeCurrent(NULL) Thread: 1362
    I/AndroidRuntime( 1362): VM exiting with result code 0, cleanup skipped.

    "org.qtproject.example.untitled4" died.

    Theres is any error?


  • Moderators

    @joanaguimas I just tested the example you posted before your current post on Android and it worked perfectly.


  • Moderators

    @joanaguimas I tested it with Qt 5.4.1 and it worked. Maybe you should try with it.
    showStatusIcon on inactive InputConnection seems to be something on Android OS side. For eg. see this SO link. Searching through bug reports points out something similar.
    I think you should try with latest version i.e Qt 5.4.1


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.