connect() doesn't seem to "connect"
-
Hi,
I've asked about this very same issue here before and I was helped. Since then, I have gone away and have now come back only to realize that I cannot seem to get it work correctly anymore... :( What I want, is to capture a double click onto a tab bar and execute a selected method upon that. I think the only thing that's changed was the header file... it looks like:
#include "session.h" #include <QHash> #include <QTabWidget> class Session; class SessionStack : public QTabWidget { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.kterminal") public: explicit SessionStack(QWidget* parent, QWidget* window); ~SessionStack(); public slots: ... ... signals: ... ... void tabBarDoubleClicked(int index); private slots: ... ... void editTabLabel(int tabIndex); private: ... ... }; #endif
and then in the respective .cpp I have:
qDebug() << "con:" << connect(this, SIGNAL(tabBarDoubleClicked(int)),this, SLOT(editTabLabel(int)));
and
void SessionStack::editTabLabel(int tabIndex) { bool ok; qDebug() << "editTabLabel!"; if (tabIndex < 0) return; QString text = QInputDialog::getText(this,tr("QInputDialog::getText()"), this->tabText(tabIndex), QLineEdit::Normal, this->tabText(tabIndex),&ok); if(ok && !text.isEmpty()) { this->setTabText(tabIndex,text); return; } }
but my editTabLabel never gets called even though the call to connect() returns true. What do I have wrong here?
Thank you!
-
Why do you declare the void tabBarDoubleClicked(int index) signal in your class? QTabWidget already has one: http://doc.qt.io/qt-5.7/qtabwidget.html#tabBarDoubleClicked
Remove the signal from your class and try again.