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. Why doesn't the connect procedure connect?

Why doesn't the connect procedure connect?

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

    Hello all. I begin as a Qt programmer.

    It's a problem about the connect procedure. I feel I miss something simple, stupid but as I don't find it, here's the question:

    Here's the problematic code:

    QTableWidget* tabView = new QTableWidget(_view);
    
    connect(tabView, SIGNAL(itemChanged(QTableWidgetItem*)), (RppDataManagementWidget*)this, SLOT(modifyDataFrame(QTableWidgetItem*)));
    

    And here's the code of the called slot:

    void RppDataManagementWidget::modifyDataFrame(QTableWidgetItem* newItem){
        std::cout << "Here it is: " << newItem->text().toStdString() << std::endl;
    }
    

    Well, it's not the whole code of the slot but the 'cout' line is a test to know if the slot is actually called. And it isn't. Nothing happens on the standard output when I:

    • double-click on a cell;
    • type some new text;
    • press enter.
      I should read "Here it is: my new text in the cell"...

    Obviously, they aren't connected. Connect is used many times in the program in the same way and it works. This line for example:

    connect(tabView->horizontalHeader(), SIGNAL(sectionResized(int, int, int)), (RppDataManagementWidget*)this, SLOT(resizeColumns(int, int, int)));
    

    works well.

    I tried other signals, like itemChanged and others. Nothing more happens...

    The only difference I spotted with other connect utlisations is that the data given to the slot as an argument is a primitive type (int, string...) while here, it's a pointer to a QTableWidgetItem.

    I have no error nor warning at the compilation, and no error message during the execution. This code is a part of a big project I'm working on...

    Who knows what I forgot?

    Patrick.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      try with connect(tabView, &QTableWidget::itemChanged, this, &RppDataManagementWidget::modifyDataFrame);

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • P Offline
        P Offline
        Patou355
        wrote on last edited by Patou355
        #3

        I tried and I got no building error, but when the tabView appears, the program crashes:
        "The program has unexpectedly finished."

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Patou355
          wrote on last edited by
          #4

          Ok, it works, the problems are somewhere else!

          Your line works but doesn't look like what I could read in the tutorials. Why?

          Thanks a lot.

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5
            • Your line works but doesn't look like what I could read in the tutorials. Why?

            Its using the new connect syntax.

            https://wiki.qt.io/New_Signal_Slot_Syntax

            the old one is the SIGNAL() and SLOT()

            The new one provides better type check and allows for functions to be used as slot.

            The old one is easier to use but might fail silently.

            One note.
            The connect returns TRUE or FALSE and its always good to check.

            1 Reply Last reply
            4
            • P Offline
              P Offline
              Patou355
              wrote on last edited by
              #6

              Ok, if I understand, my initial syntax is "legacy" syntax. Should I replace them by the new syntax in the entire program?

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                @Patou355

                Using the new syntax will help maintenance.
                So I would considered it worth the time to replace.

                Note that for a few overloaded function the needed syntax is pretty ugly

                connect(cmbProfiles,
                static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged),
                this,
                &MyClass::loadProfilesDetails);

                https://forum.qt.io/topic/20998/qt5-new-signals-slots-syntax-does-not-work-solved/8

                1 Reply Last reply
                3
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi,

                  To add to @mrjj, you can use the qOverload method avoid that ugly syntax.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  kshegunovK 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    Hi,

                    To add to @mrjj, you can use the qOverload method avoid that ugly syntax.

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by
                    #9

                    @SGaist said in Why doesn't the connect procedure connect?:

                    To add to @mrjj, you can use the qOverload method avoid that ugly syntax.

                    Also a rather nifty trick I recently became aware of:

                    connect<void (QComboBox::*)(const QString &)>(cmbProfiles, &QComboBox::currentIndexChanged, this, &MyClass::loadProfilesDetails);
                    

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    1

                    • Login

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