Results 1 to 3 of 3

Thread: How to access a signal of a button present in one qml file from another qml file?

  1. #1
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: How to access a signal of a button present in one qml file from another qml file?

    There is a qml file with the code for a button.

    I wish to define a slot to that signal in another qml file.

    How should I go about this?


    Added after 5 minutes:


    SOLVED:

    ButtonA.qml is the file containing signal.
    I wrote the slot in other file like:

    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. Item
    4. {
    5. ButtonA
    6. {
    7. Component.onCompleted:
    8. {
    9. send.connect (functionNameA);
    10. send ("What?")
    11. }
    12.  
    13. function functionNameA (notice)
    14. {
    15. console.log ("Sending notice: " + notice)
    16. }
    17.  
    18. onSend:
    19. {
    20. console.log ("send signal emitted with notice: " + notice)
    21. }
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by TheIndependentAquarius; 18th October 2013 at 10:51.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to access a signal of a button present in one qml file from another qml file?

    You could also use the standard signal handler, i.e. "on" followed by the signal name, first letter capitalized.

    E.g. ButtonA-qml
    Qt Code:
    1. Item {
    2. signal send(string text)
    3. }
    To copy to clipboard, switch view to plain text mode 
    Signal "send" -> signal handler "onSend"
    Qt Code:
    1. ButtonA {
    2. onSend: console.log("send(" + text + ")")
    3. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    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: How to access a signal of a button present in one qml file from another qml file?

    Or a Connections element.
    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.


Similar Threads

  1. Access to js imported file in another qml file
    By alizadeh91 in forum Qt Quick
    Replies: 5
    Last Post: 16th July 2012, 15:21
  2. present data in tabular form reading from a file
    By sachinmcajnu in forum Qt Programming
    Replies: 1
    Last Post: 2nd April 2011, 14:53
  3. Replies: 3
    Last Post: 2nd April 2011, 13:13
  4. How to postpone a signal until present form is closed ?
    By marcvanriet in forum Qt Programming
    Replies: 6
    Last Post: 15th December 2010, 12:22
  5. Replies: 2
    Last Post: 2nd April 2008, 17:28

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.