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. connect() doesn't seem to "connect"

connect() doesn't seem to "connect"

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 686 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.
  • cerrC Offline
    cerrC Offline
    cerr
    wrote on last edited by A Former User
    #1

    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!

    jsulmJ 1 Reply Last reply
    0
    • cerrC cerr

      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!

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

      @cerr

      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.

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

      1 Reply Last reply
      4
      • cerrC Offline
        cerrC Offline
        cerr
        wrote on last edited by
        #3

        Bang, that was it! Thank you! :)

        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