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. [Solved]Dynamically connect parent signal to current tab function in tab widget.

[Solved]Dynamically connect parent signal to current tab function in tab widget.

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.3k 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.
  • S Offline
    S Offline
    SetBetterPass
    wrote on last edited by
    #1

    I have mainwindow with tab widget and I want dynamically connect signals from mainwindow menu bar to actual tab widget function. For example if I have 2nd tab action find will find matches in 2nd tab, if I have 3rd tab it'll look in 3rd tab etc. But I just can't find out how to access the function in actual tab widget, I have code:
    @
    //in constructor:
    connect(ui->actionNew_tab,SIGNAL(triggered()),this,SLOT(addTab()));
    connect(ui->tabWidget,SIGNAL(currentChanged(int)),this,SLOT(tabChanged()));

    void MainWindow::addTab(){
    mainTab *tab=new mainTab(this);
    ui->tabWidget->addTab(tab,"Download "+QByteArray::number(ui->tabWidget->count()+1));
    }
    void MainWindow::tabChanged(){
    disconnect(ui->actionDownload,SIGNAL(triggered()),oldTab,SLOT(find()));
    connect(ui->actionDownload,SIGNAL(triggered()),actualTab,SLOT(find()));
    }
    @

    but the problem is I can't access function find(), I tried ui->tabWidget, ui->tab and ui->tabWidget->currentWidget() but neither contains it. (I don't even know how to disconnect previous signal because I cant access it). Please help a newbie out with his problem, thanks :)

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      What is find() supposed to be? A slot of mainTab?

      In addition, I most probably wouldn't disconnect() / connect() at all; add a slot to MainWindow which is connected to ui->actionDownload and simply calls actualTab->find().

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SetBetterPass
        wrote on last edited by
        #3

        Sorry my post is a bit confusing, I had terrible headache when I was typing it. Find() is slot of each tab and I want to use it to look to find matches in it's QStringList variable. Uhm I should probably try only make one Find() slot in MainWindow and look in actual tab list.
        I found out why I can't access the data, it was simple, I had to declare mainTab* tab as global variable. My actual problem is when I declare it this way:
        @
        //in header file
        mainTab* tab;
        //function
        void MainWindow::addTab(){
        tab=new mainTab(this);
        ui->tabWidget->addTab(tab,"Download "+QByteArray::number(ui->tabWidget->count()+1));
        }
        @
        tab is pointing only to last tab created, so I can't acces variables from previous declared tabs, I tried to do it this way:
        @
        //in header
        QList<mainTab> tab;
        //function
        void MainWindow::addTab(){
        tab->append(new mainTab(this));
        ui->tabWidget->addTab(tab->at(tab->count()-1),"Download"+QByteArray::number(ui->tabWidget->count()+1));
        }@
        but this gave me errors:
        error: no matching function for call to ‘QList<mainTab>::append(mainTab
        )’
        error: no matching function for call to ‘QTabWidget::addTab(const mainTab&, const QByteArray)’

        If someone can help me with this it would be nice, I think this isn't the best way to make tabs so if there is some better way please correct me, or if I can access the variables from previous made tabs declared the first method I did. I have to go afk now, will look at it later today, thanks for any help.

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

          Hi,

          QList<mainTab> is "wrong", you can't have QList of QObject as the copying QObject is forbidden.

          QList<mainTab> * is also a bad idea, generally you don't need pointers to QList object.

          Following your code you should have a QList<mainTab*>.

          You could however also use the "findChildren":http://qt-project.org/doc/qt-4.8/qobject.html#findChildren template function to get a list of mainTab from your QTabWidget.

          Hope it helps

          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
          • S Offline
            S Offline
            SetBetterPass
            wrote on last edited by
            #5

            [quote author="SGaist" date="1364376934"]
            Following your code you should have a QList<mainTab*>.[/quote]

            Thank you very much this is working :)

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

              You're welcome !

              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

              • Login

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