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. Passing parameters to slots

Passing parameters to slots

Scheduled Pinned Locked Moved General and Desktop
18 Posts 5 Posters 4.7k 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 have a slot that takes an int as a parameter. However when I call the slot and put a number into the parenthesis, it gives me this error:

    @QObject::connect: No such slot browseTab::loadBar(25)@

    how do I pass a value into the function?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ankursaxena
      wrote on last edited by
      #2

      have u defined slot in header file correctly ?? and are u defined connect method for calling this slot ??

      means if u defined connect method then slot's passing parameter type should be same as signal's parameter type.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qxoz
        wrote on last edited by
        #3

        Can you show, how do you make connection?

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

          ok here is my connect:
          @connect(webView, SIGNAL(loadProgress(int)), SLOT(loadBar(25)));@
          I need to pass a value of 25 to the loadBar function (to show the QWebView is 25% loaded)

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            qxoz
            wrote on last edited by
            #5

            Well if you use Qt4:

            1. Using two pairs of signal and slot
            2. Using "QSignalMapper":http://qt-project.org/doc/qt-4.8/qsignalmapper.html#details

            In Qt5 you also can use functors "Signal and slot":http://qt-project.org/doc/qt-5/signalsandslots.html
            something like that:
            @connect(sender, &QObject::loadProgress, ={ this->loadBar(25); });@

            but just curious why you want always show loading progress as 25%?

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              [quote author="nicky j" date="1393303099"]ok here is my connect:
              @connect(webView, SIGNAL(loadProgress(int)), SLOT(loadBar(25)));@
              I need to pass a value of 25 to the loadBar function (to show the QWebView is 25% loaded)[/quote]The signal parameter is copied into the slot parameter.

              When the QWebView emits the loadProgress() signal, it will carry an int value. Your loadBar() slot will automatically receive that value.

              Write this instead:
              @connect(webView, SIGNAL(loadProgress(int)),
              this, SLOT(loadBar(int)));@

              if you want to call loadBar() without waiting for a signal, just call it like a regular function:
              @this->loadBar(25);@

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • IamSumitI Offline
                IamSumitI Offline
                IamSumit
                wrote on last edited by
                #7

                hello nlcky ,

                here you are passing 25 directly to your slot which will give an error .
                Donn't pass 25 in direct manner.

                Be Cute

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

                  Ok thanks for the help!

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

                    ok so I changed the connect function to:
                    @connect(webView, SIGNAL(loadProgress(int)), SLOT(loadBar(int)));@
                    It compiles, but doesn't seem to be called whenever the webView is loading.
                    Im starting to think its trouble with the slot itself:

                    @void browseTab::loadBar(int progress)
                    {
                    if(progress <= 25)
                    {
                    SearchBar->setStyleSheet(
                    "border-right:2px solid blue;"
                    );
                    }
                    if(progress == 50)
                    {
                    SearchBar->setStyleSheet(
                    "border-right:2px solid blue;"
                    "border-bottom:2px solid blue;"
                    );
                    }
                    if(progress == 75)
                    {
                    SearchBar->setStyleSheet(
                    "border-right:2px solid blue;"
                    "border-bottom:2px solid blue;"
                    "border-left:2px solid blue;"
                    );
                    }
                    if(progress == 100)
                    {
                    SearchBar->setStyleSheet(
                    "border-right:2px solid blue;"
                    "border-bottom:2px solid blue;"
                    "border-left:2px solid blue;"
                    "border-top:2px solid blue;"
                    );
                    }
                    if(progress == 101)
                    {
                    SearchBar->setStyleSheet(
                    "border-right:2px solid black;"
                    "border-bottom:2px solid black;"
                    "border-left:2px solid black;"
                    "border-top:2px solid black;"
                    );
                    }
                    }@

                    Basically I'm using the searchBar as a progress bar by changing the color of the sides as the page loads. Obviously it is not working. Ideas?

                    1 Reply Last reply
                    0
                    • JKSHJ Offline
                      JKSHJ Offline
                      JKSH
                      Moderators
                      wrote on last edited by
                      #10

                      To check if a slot is called, stick a qDebug() inside it.

                      Also, you check if progress equals a particular value. Your slot won't do anything if it receives 49 or 51. It's best not to assume that every value between 1 and 100 will be received.

                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

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

                        yes int progress = 0. Should I change that? If not every value will be called, what should I do in the if() statements that are called when it reaches certain points? Is there a range of values I should call? if so, how do I do that?

                        1 Reply Last reply
                        0
                        • JKSHJ Offline
                          JKSHJ Offline
                          JKSH
                          Moderators
                          wrote on last edited by
                          #12

                          You don't get to choose which values you receive -- QWebView is responsible for that.

                          Use qDebug() to print the value of progress each time your slot is called. That should help you decide what to do.

                          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

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

                            ok I removed the default value from int progress. There is still nothing happening

                            1 Reply Last reply
                            0
                            • JKSHJ Offline
                              JKSHJ Offline
                              JKSH
                              Moderators
                              wrote on last edited by
                              #14

                              Use qDebug() to print progress. (Removing the default value should have no effect whatsoever)

                              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

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

                                where do I place qDebug()?

                                1 Reply Last reply
                                0
                                • JKSHJ Offline
                                  JKSHJ Offline
                                  JKSH
                                  Moderators
                                  wrote on last edited by
                                  #16

                                  What debugging techniques are you familiar with? Have you used printf() before?

                                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

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

                                    nope Ive never used printf() or qDebug() before

                                    1 Reply Last reply
                                    0
                                    • JKSHJ Offline
                                      JKSHJ Offline
                                      JKSH
                                      Moderators
                                      wrote on last edited by
                                      #18

                                      See "QDebug | Basic Use":http://qt-project.org/doc/qt-5/QDebug.html#basic-use for an example.

                                      It is a very simple but very useful technique to check your program. If you put qDebug() in a function, it will print a message in your Application Output pane* every time that function is called. If the message doesn't appear, that means your function hasn't been called. once you play with it, I'm sure you can think of other uses for qDebug().

                                      Use qDebug() to:

                                      Check if loadBar() is called

                                      Examine the value of progress inside loadBar()

                                      *(If you don't know where the Application Output pane is, search the "Qt Creator | User Interface":http://qt-project.org/doc/qtcreator-3.0/creator-quick-tour.html#application-output page)

                                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                      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