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. QInputDialog pops up multiple times after being closed with "OK"

QInputDialog pops up multiple times after being closed with "OK"

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.4k 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.
  • cerrC Offline
    cerrC Offline
    cerr
    wrote on last edited by
    #1

    Hi,

    First off, I'm a newbie and I got help in this forum to get the below achieved (but I think I'm still missing something):
    I launch a QInputDialog (to change the tab's label) with a double lick on a QTabWidget which seems to work except for the reason that after the first time entering a new label and hitting okay, the dialog box pops right up again for three times before it finally disappears for good and I'm wondering why.
    How this looks in code:

    QWidget *tabWidget = QTabWidget::widget(tabIndex);
        connect(this, SIGNAL(tabBarDoubleClicked(int)),this, SLOT(editTabLabel(int)));
    
    void SessionStack::editTabLabel(int tabIndex)
    {
        bool ok;
      
        if (tabIndex < 0)
            return;
        
        QString tab_label = QString("Shell (") + QString::number(tabIndex, 16) + ")";
        QString text = QInputDialog::getText(this,tr("QInputDialog::getText()"),
    					QString("Tab Title("+QString::number(tabIndex, 16)+"):"), QLineEdit::Normal,
    					tab_label,&ok);
        if(ok && !text.isEmpty()) {
            // set the new label
            QWidget *TabWidget = QTabWidget::widget(tabIndex);
            this->setTabText(tabIndex,text);
            return;
        }
    }
    

    Why would thsi be? Any hints and clues are appreciated!

    raven-worxR 1 Reply Last reply
    0
    • cerrC cerr

      Hi,

      First off, I'm a newbie and I got help in this forum to get the below achieved (but I think I'm still missing something):
      I launch a QInputDialog (to change the tab's label) with a double lick on a QTabWidget which seems to work except for the reason that after the first time entering a new label and hitting okay, the dialog box pops right up again for three times before it finally disappears for good and I'm wondering why.
      How this looks in code:

      QWidget *tabWidget = QTabWidget::widget(tabIndex);
          connect(this, SIGNAL(tabBarDoubleClicked(int)),this, SLOT(editTabLabel(int)));
      
      void SessionStack::editTabLabel(int tabIndex)
      {
          bool ok;
        
          if (tabIndex < 0)
              return;
          
          QString tab_label = QString("Shell (") + QString::number(tabIndex, 16) + ")";
          QString text = QInputDialog::getText(this,tr("QInputDialog::getText()"),
      					QString("Tab Title("+QString::number(tabIndex, 16)+"):"), QLineEdit::Normal,
      					tab_label,&ok);
          if(ok && !text.isEmpty()) {
              // set the new label
              QWidget *TabWidget = QTabWidget::widget(tabIndex);
              this->setTabText(tabIndex,text);
              return;
          }
      }
      

      Why would thsi be? Any hints and clues are appreciated!

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @cerr
      when the shown connect statement is the only place where editTabLabel() is called, there must be some other code causing your issue.
      Also you can conenct with the debugger, set a breakpoint in the method and check the stack trace where the call comes from.

      Also is this the complete code?
      Because the 2 calls to QTabWidget::widget(tabIndex) never use the returned widget.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      cerrC 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @cerr
        when the shown connect statement is the only place where editTabLabel() is called, there must be some other code causing your issue.
        Also you can conenct with the debugger, set a breakpoint in the method and check the stack trace where the call comes from.

        Also is this the complete code?
        Because the 2 calls to QTabWidget::widget(tabIndex) never use the returned widget.

        cerrC Offline
        cerrC Offline
        cerr
        wrote on last edited by cerr
        #3

        @raven-worx said in QInputDialog pops up multiple times after being closed with "OK":

        @cerr
        when the shown connect statement is the only place where editTabLabel() is called, there must be some other code causing your issue.
        Also you can conenct with the debugger, set a breakpoint in the method and check the stack trace where the call comes from.
        @raven-worx

        I haven't gotten to it yet but I've realized in the meantime that the dialog box pops up, once for every tab I have open...

        Also is this the complete code?

        No, this is not the complete code. There's more to it, I don't show where i do addTab() either. I just extracted the connect and the respective slot.

        Because the 2 calls to QTabWidget::widget(tabIndex) never use the returned widget.

        That is correct, it has to be cleaned up, these are left overs. Booh! :o

        jsulmJ 1 Reply Last reply
        0
        • cerrC cerr

          @raven-worx said in QInputDialog pops up multiple times after being closed with "OK":

          @cerr
          when the shown connect statement is the only place where editTabLabel() is called, there must be some other code causing your issue.
          Also you can conenct with the debugger, set a breakpoint in the method and check the stack trace where the call comes from.
          @raven-worx

          I haven't gotten to it yet but I've realized in the meantime that the dialog box pops up, once for every tab I have open...

          Also is this the complete code?

          No, this is not the complete code. There's more to it, I don't show where i do addTab() either. I just extracted the connect and the respective slot.

          Because the 2 calls to QTabWidget::widget(tabIndex) never use the returned widget.

          That is correct, it has to be cleaned up, these are left overs. Booh! :o

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @cerr Sounds like you're connection to the signal for each tab. That's why the slot is called several times.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2

          • Login

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