Reply
Thread Tools
Posts: 20 | Thanked: 12 times | Joined on Nov 2010
#1
Hi,
I'm trying to get to grips with QT, c++ and QML all at the same time, so please bear with me.

I have been modifying the RSSNews project that come included with the Nokia QT SDK 1.1 (and possibly others, but that's where I found it). I've got it doing almost exactly what I've decided is my target except for one thing.

I can't get it to follow the <link> tags from the rss feeds. I've modified it so that it goes to some other feeds, one of which is a list of PDF files. I figured that rather than trying to get Poppler working, I could just pass out the link in the feed to MicroB using:

Code:
QDesktopServices::OpenUrl (QUrl(link))
I've clearly misunderstood something vital, because the SDK keeps telling me there's an unexpected token ':' if I just include this line in the onClicked bit of the MouseArea of the text like this:
Code:
Item {
    id: delegate
    height: column.height + 40
    width: delegate.ListView.view.width

    Column {
        id: column

        x: 20; y: 20
        width: parent.width - 40

        signal selected
        
        Text {
            id: titleText
            text: title; width: parent.width; wrapMode: Text.WordWrap;

           //Some formatting to change colour based on category is here...
            MouseArea {
                id: mouseArea
                anchors.fill: parent
                onClicked: onClicked: {column.selected();
                    console.log (link);
                    //QDesktopServices::OpenUrl (link);
                 }
            }


        }

        Text {
            id: descriptionText
            width: parent.width; text: description
            wrapMode: Text.WordWrap;
            font { family: "Helvetica";
                 pointSize: {if (title == "Info")
                         return 8
                    else
                         return 16}
                }
            color: "white"

        }

    }

    Rectangle {
        width: parent.width; height: 1; color: "#cccccc"
        anchors.bottom: parent.bottom
    }
}
I've got QDesktopServices imported in the main.cpp file, but I'm obviously using it wrong.

I've tried reading up about signals and slots, on the assumption that I need to pass a signal about the mouse click back to a slot in the main.cpp, but I've got completely lost and can't see how to apply what I've read to my situation.

Please can someone help me get this back on track?

Many thanks,
Alyn.

Last edited by alynsparkes; 2011-02-21 at 17:16.
 
Posts: 324 | Thanked: 371 times | Joined on Dec 2009 @ Vancouver, BC
#2
You'd need to either:
- create a C++ object with the required function, and declare it to your QML script so you can call that function
- emit a signal in QML, and link it to a slot in your C++ classes

Or more easily, use : http://doc.trolltech.com/4.7/qml-qt....ernally-method
so, just replace what you had with:
Qt.openUrlExternally(link)
 

The Following 2 Users Say Thank You to Slocan For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 00:44.