Results 1 to 8 of 8

Thread: Signal and Slots with QML confusion with QML items

  1. #1
    Join Date
    Oct 2009
    Posts
    47
    Thanks
    10

    Default Signal and Slots with QML confusion with QML items

    Hi,

    I was wondering if anyone can explain how SIgnals and Slots work in QML.

    I understand them in Qt.

    So if I have 2 files.
    A.qml

    B.qml


    I want A.qml to send a signal to B.qml

    The signal I want A to send to B is a string.

    //A.qml

    Qt Code:
    1. Item
    2. {
    3. id: aItem
    4.  
    5.  
    6. signal sendStringSignal
    7.  
    8. Rectangle
    9. {
    10. onClicked: { //need to send a to B.qml }
    11.  
    12. }
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 


    I wasn't able to find code snippets of anyone doing this, any ideas?

    Thanks

  2. #2
    Join Date
    Nov 2010
    Posts
    48
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Signal and Slots with QML confusion with QML items

    Quote Originally Posted by technoViking View Post
    Hi,

    I was wondering if anyone can explain how SIgnals and Slots work in QML.

    I understand them in Qt.

    So if I have 2 files.
    A.qml

    B.qml


    I want A.qml to send a signal to B.qml

    The signal I want A to send to B is a string.

    //A.qml

    Qt Code:
    1. Item
    2. {
    3. id: aItem
    4.  
    5.  
    6. signal sendStringSignal
    7.  
    8. Rectangle
    9. {
    10. onClicked: { //need to send a to B.qml }
    11.  
    12. }
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 


    I wasn't able to find code snippets of anyone doing this, any ideas?

    Thanks
    Rectangle {

    onClicked: { container.clicked(); }
    }

  3. #3
    Join Date
    Oct 2009
    Posts
    47
    Thanks
    10

    Default Re: Signal and Slots with QML confusion with QML items

    Thanks so that seems to be sending a clicked() signal but I don't see how you can send a string through that signal and how does the other .qml file accept that signal, aka how does it make a slot to receive the string?

  4. #4
    Join Date
    Nov 2010
    Posts
    48
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Signal and Slots with QML confusion with QML items

    Quote Originally Posted by technoViking View Post
    Thanks so that seems to be sending a clicked() signal but I don't see how you can send a string through that signal and how does the other .qml file accept that signal, aka how does it make a slot to receive the string?
    Please refer to the example C:\Qt\4.7.0\demos\declarative\flickr. it has got everything, hope this will help you.

  5. The following user says thank you to somnathbanik for this useful post:

    technoViking (8th November 2010)

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signal and Slots with QML confusion with QML items

    Quote Originally Posted by technoViking View Post
    Thanks so that seems to be sending a clicked() signal but I don't see how you can send a string through that signal and how does the other .qml file accept that signal, aka how does it make a slot to receive the string?
    In QtQuick you usually use property binding which is a higher-level mechanism than signals and slots (and it uses signals under the hood in case of C++ code). Most of the times signals are used as notification of some property changes and all you need to do is to follow this pattern - you declare a property in one object and write a statement in the other object that uses the name of the property defined earlier.

    Here is a dirty example:
    javascript Code:
    1. import Qt 4.7
    2.  
    3. Rectangle {
    4. id: win
    5. width: 200
    6. height: 200
    7.  
    8. TextInput {
    9. anchors.top: win.top; anchors.left: win.left; anchors.right: win.right;
    10. id: objectA
    11. text: "xyz"
    12. height: 100
    13. }
    14.  
    15. Text {
    16. id: objectB
    17. anchors.bottom: win.bottom; anchors.left: win.left; anchors.right: win.right;
    18. height: 100
    19. text: "=>"+objectA.text+"<="
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 

    Try changing the text of the first object and see what happens.

    Remember QML is a declarative language. You declare text of objectB to be the text of objectA surrounded by arrows.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #6
    Join Date
    Oct 2009
    Posts
    47
    Thanks
    10

    Default Re: Signal and Slots with QML confusion with QML items

    I see, I didn't realize that's the proper way of doing things. It seems like that would make a ton of global objects, and everyone is simply modifying the global objects

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Signal and Slots with QML confusion with QML items

    Quote Originally Posted by technoViking View Post
    I see, I didn't realize that's the proper way of doing things.
    It's not a "proper" way, it's one of the ways that is more declarative than using signals and slots directly (which is imperative).

    It seems like that would make a ton of global objects, and everyone is simply modifying the global objects
    You don't need to modify any global objects, you can create a local alias to a property of another object. Or maybe I don't understand what you mean by those global objects... hmm...

    It would be best if you explained what do you need all this for and maybe then we'll be able to find a solution tailored for the specific situation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    technoViking (10th November 2010)

  10. #8
    Join Date
    Oct 2009
    Posts
    47
    Thanks
    10

    Default Re: Signal and Slots with QML confusion with QML items

    Thanks for the response. I will get a better description in a few!

Similar Threads

  1. Signal/Slots, Where can i use it?
    By Tio in forum Newbie
    Replies: 2
    Last Post: 25th May 2010, 02:36
  2. Confusion about events posted from slots
    By elizabeth.h1 in forum Qt Programming
    Replies: 1
    Last Post: 29th September 2009, 11:05
  3. signal slot confusion
    By mstegehu in forum Qt Programming
    Replies: 6
    Last Post: 31st August 2009, 12:41
  4. Signal and slots
    By villy in forum Qt Programming
    Replies: 1
    Last Post: 12th January 2007, 11:10
  5. QSortFilterProxyModel signal and selection confusion
    By pascal123 in forum Qt Programming
    Replies: 1
    Last Post: 1st April 2006, 17:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.