Unsolved QInputDialog pops up multiple times after being closed with "OK"
-
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!
-
@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. -
@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-worxI 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
-
@cerr Sounds like you're connection to the signal for each tab. That's why the slot is called several times.