Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Parameters in Slots
QtWS25 Last Chance

Parameters in Slots

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nicky j
    wrote on last edited by
    #1

    Hey there,

    I am having some trouble with slots & signals in my program.
    my mainView class contains a slot called 'launchApp', launchApp accepts a QString as a parameter as you can see below:
    @void mainView::launchApp(QString appName)
    {
    if(appName == "music")
    {

    }
    

    }@

    meanwhile I have a button in another class called 'sideBar'. when this button is clicked it calls mainView::launchApp:
    @
    connect(launchMusicAppButton, SIGNAL(clicked()), mainView_object_pointer, SLOT(launchApp("music")));
    @
    when I run my application I get this error:
    QObject::connect: No such slot mainView::launchApp("music")

    I believe that the problem lies in how I am declaring the parameter of launchApp. How can I have "music" as a parameter of launchApp? It is designed to accept QStrings as you can see above.

    Thanks for your help!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      steno
      wrote on last edited by
      #2

      I would read up on the documentation about signals and slots. It seems that you missed something. The connect should be failing on you. You pass parameters through calling emit which then calls the slot with the parameter. You either have to create a slot to connect to clicked and then a signal to fire in the slot that passes a string, or like into QSignalMapper.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nicky j
        wrote on last edited by
        #3

        so the parameter should be in clicked() instead of launchApp()?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          steno
          wrote on last edited by
          #4

          No, you have to catch the clicked signal, and in that slot refire another signal with a string, or use a QSignalMapper to map the clicked signal to a slot that takes a string. The parameters of the signal slot pair have to be the same. The clicked signal, if i recall doesn't have any parameters.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            steno
            wrote on last edited by
            #5

            Something of this nature.

            @
            siganls:
            void launchApp(QString name);

            protected slots:
            void myClicked()
            @

            @
            connect(button,SIGNAL(clicked()), object,SLOT(myClicked()));
            connect(object,SIGNAL(launchApp(QString)),someOtherObj,SLOT(launchApp(QString)));
            @

            @
            void myObject::myClicked()
            {
            emit launchApp("music");
            }
            @

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Also consider using QSignalMapper. Alternatively, you could use a lambda function as your slot.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved