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 another argument to a SLOT
Forum Updated to NodeBB v4.3 + New Features

Passing another argument to a SLOT

Scheduled Pinned Locked Moved General and Desktop
18 Posts 6 Posters 5.2k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    Phenixo
    wrote on last edited by
    #1

    hello
    @connect(QWebVIew(),SIGNAL(titleChanged(QString)),this, SLOT(myslot(QString*,int*)));
    @
    i must pass an intiger with th QString

    to be a professional programmer is my goal :p

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      You can connect your signal to a one-arg slot, in the slot, you can call the two-args slot.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Phenixo
        wrote on last edited by
        #3

        i didn't understand what have you said.
        ijust want to pass 2 argument the qstring and the int

        to be a professional programmer is my goal :p

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dbzhang800
          wrote on last edited by
          #4

          OK, the simply answer is: you can't .

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

            As 1+1=2 said - you can't do that. But you can call myslot(QString*,int*) manually from another slot and pass arguments which you need.

            1 Reply Last reply
            0
            • JeroentjehomeJ Offline
              JeroentjehomeJ Offline
              Jeroentjehome
              wrote on last edited by
              #6

              Or use a qsignalmapper to "parse" the signals into slots with other arguments.

              Greetz, Jeroen

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Phenixo
                wrote on last edited by
                #7

                I have read the qsignalmapper class in the exemple it show how pass one argument the cliqued signal don't pass an argument
                i want to pass two variable the QString from the titilechanged and the int from my methode

                to be a professional programmer is my goal :p

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Like the others said, it's not possible to have a slot with more arguments than the signal.

                  Use an intermediate slot that will call your function with the necessary parameters.

                  Also, are you sure you want to use pointers to QString and int in your slot ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Phenixo
                    wrote on last edited by
                    #9

                    @void mainWind::changetab(int index)
                    {
                    if(ui->tabWidget->indexOf(ui->newtab)==index)
                    {
                    addtab();

                    }
                    

                    currentpage(()->settings()->setIconDatabasePath("a");
                    url(currentPages()->url());
                    connect(currentpage((),SIGNAL(loadProgress(int)),ui->progressBar,SLOT(setValue(int)));
                    connect(currentpage((),SIGNAL(loadStarted()),this,SLOT(depart()));
                    connect(currentpage((),SIGNAL(loadFinished(bool)),this,SLOT(finish(bool)));
                    connect(currentpage((),SIGNAL(loadProgress(int)),this,SLOT(laodPage(int)));
                    connect(currentpage((),SIGNAL(titleChanged(QString)),this,SLOT(titl(QString)));
                    connect(currentpage((),SIGNAL(urlChanged(QUrl)),this,SLOT(url(QUrl)));
                    connect(currentpage((),SIGNAL(iconChanged()),this,SLOT(icon()));

                    }@
                    @
                    QWebView *mainWind:: currentpage()
                    {
                    if(ui->tabWidget->currentWidget()->findChild<QWebView *>()==0)
                    {
                    int a=ui->tabWidget->currentIndex()-1;
                    return ui->tabWidget->widget(a)->findChild<QWebView *>();

                    }
                    else
                    {
                        return ui->tabWidget->currentWidget()->findChild<QWebView *>();
                    }
                    

                    }
                    @
                    @
                    void mainWind::titre(const QString & titre)
                    {
                    QString titr(titre);
                    if(titre.size()>40)
                    {
                    titr=titre.left(40)+"....";
                    }
                    ui->tabWidget->setTabText(m_index,titr);
                    }
                    @
                    so when i load a page and I dont change the tab all is ok. but when i leave the page to load and i change the tab. the name of the page load is in the newtab because it is now the current tab. i have the page in a tab and its name in the other tab.
                    so thats why i want to pass index of the widget (that well be changing the titl

                    to be a professional programmer is my goal :p

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Then in your slot use sender() to get the widget that emitted the signal and use that to find the right tab to update.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        Phenixo
                        wrote on last edited by
                        #11

                        thx for answering my question
                        if you can please tell me how to use the sender i have read the doc but i didn't understand very well can you please give me a simple example in general.

                        to be a professional programmer is my goal :p

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          sender() returns a pointer to the object that emitted the signal. In your case (if I understood correctly) it's one of the widget in the QTabWidget.

                          You can cast (using qobject_cast) that pointer to QWidget * and then get the tab index using indexOf and update the correct tab text with it.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            Phenixo
                            wrote on last edited by
                            #13

                            thx
                            [quote author="SGaist" date="1377806355"]sender() returns a pointer to the object that emitted the signal. In your case (if I understood correctly) it's one of the widget in the QTabWidget. [/quote]

                            but the QObject that emitted the signal is a QWebView which is contain in a QTabWidget can i have a access to the tab with a pointer of QWebView
                            fanction like "findChild" but in this one i have to find the parent
                            thx again

                            to be a professional programmer is my goal :p

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              You don't need that, since you call addTab with a QWebView you can retrieve the corresponding index with the pointer given by sender() once you casted it.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • P Offline
                                P Offline
                                Phenixo
                                wrote on last edited by
                                #15

                                QObject * QObject::sender() const [protected] where do i declare this methode, in which slot.
                                i have also this slot
                                @void mainWind::addtap()
                                {
                                QWidget *tap=new QWidget();
                                QVBoxLayout *layout = new QVBoxLayout();
                                QWebView *webpage=new QWebView();
                                pageWeb->settings()->setIconDatabasePath("a");
                                layout->addWidget(webpage);
                                tap->setLayout(layout);
                                webpage->load(QUrl(""));
                                ui->tabWidget->insertTab(ui->tabWidget->indexOf(ui->newTap),tap,"");
                                ui->tabWidget->setCurrentWidget(tap);
                                changetap(ui->tabWidget->indexOf(tap));

                                }@

                                to be a professional programmer is my goal :p

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  You don't declare that method. You call it at the start of the slot

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  0
                                  • K Offline
                                    K Offline
                                    KA51O
                                    wrote on last edited by
                                    #17

                                    see the doc of "QObject::sender()":http://qt-project.org/doc/qt-4.8/qobject.html#sender .

                                    1 Reply Last reply
                                    0
                                    • P Offline
                                      P Offline
                                      Phenixo
                                      wrote on last edited by
                                      #18

                                      @void mainWind::titre(const QString & titre)
                                      {
                                      QWidget *a= qobject_cast<QWidget *>(sender());
                                      QString titr(titre);
                                      if(titre.size()>40)
                                      {
                                      titr=titre.left(40)+"....";
                                      }
                                      ui->tabWidget->setTabText(ui->tabWidget->indexOf(a)),titr);
                                      }@
                                      is this correct

                                      to be a professional programmer is my goal :p

                                      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