Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Passing another argument to a SLOT
Qt 6.12 LTS is out! See what's new in the release blog

Passing another argument to a SLOT

Scheduled Pinned Locked Moved General and Desktop
18 Posts 6 Posters 7.1k 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.
  • 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
    • ? Offline
      ? Offline
      A Former User
      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

      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
        • ? Offline
          ? Offline
          A Former User
          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.

          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
            • ? Offline
              ? Offline
              A Former User
              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

              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
                • ? Offline
                  ? Offline
                  A Former User
                  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));

                  }@

                  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
                    • ? Offline
                      ? Offline
                      A Former User
                      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
                      • ? Offline
                        ? Offline
                        A Former User
                        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

                        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
                        • Unsolved