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. Regarding QTabWidget and QSignalMapper
Forum Updated to NodeBB v4.3 + New Features

Regarding QTabWidget and QSignalMapper

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.5k 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.
  • U Offline
    U Offline
    unmeshphalak
    wrote on last edited by
    #1

    hello all, i want to fire a command which is a QString when a particular tab is selected using QSignalMapper depending on the tab_index i have selected.
    @
    connect(tab_widget, SIGNAL(currentChanged(int)), signal_mapper, SLOT(map()));
    @
    This doesn't work for me as map() slot don't take any arguments.
    Please help me with the same or show me other way round to do this stuff.

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

      QSignapMapper is not the class you are looking for. QTabWidget already has a signal that contains an index for the selected tab. You can use that to make a mapping to a string yourself. Simply use a QStringList to store the strings, and lookup the corresponding string for each index, and then re-emit the signal with the string.

      1 Reply Last reply
      0
      • U Offline
        U Offline
        unmeshphalak
        wrote on last edited by
        #3

        thanks andre for your suggestion but i want to make it work according to my design::-
        i want to store the strings as a property for each child widgets of QTabWidget by using setProperty() in a function set_command() where i pass qtabwidget, index of tab, string as an argument.
        So that when currentChanged() signal is emitted, it inquires the property of its current active widget and fires command.
        Also i dont want to store the strings as member variable in QStringList.
        Please do suggest, how to use signal slot in this case.

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

          That was not the design you described in your first post, but ok. It is still simple. You can indeed also store the strings as a property in the tab widgets themselves. I think I would do something like this:

          @
          //header

          class MyTabWidget: public QTabWidget {
          Q_OBJECT

          public:
          MyTabWidget(QWidget* parent=0);

          signals:
          void currentChanged(QString);

          private slots:
          void onCurrentChanged(int index);
          }

          // implementation
          MyTabWidget::MyTabWidget(QWidget* parent):
          QTabWidget(parent)
          {
          connect(this, SIGNAL(currentChanged(int)), this, SLOT(onCurrentChanged(int)));
          }

          void MyTabWidget::onCurrentChanged(int index)
          {
          QWidget* w = widget(index);
          if (w) {
          QString s = w->property("theStringProperty").toString();
          if (!s.isEmpty()) emit currentChanged(s);
          }
          }
          @

          This should (not tested, brain to forum) emit a currentChanged(QString) signal if they have a QString property theStringProperty set.

          1 Reply Last reply
          0
          • U Offline
            U Offline
            unmeshphalak
            wrote on last edited by
            #5

            thanks Andre, it really helped me.
            sorry for not posting details previous only.

            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