Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QObject::connect() gives error
Qt 6.12 LTS is out! See what's new in the release blog

QObject::connect() gives error

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 2.0k 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.
  • H Offline
    H Offline
    HenkCoder
    wrote on last edited by
    #1

    Hello everyone,
    I was trying to connect a signal and a slot:

        connect(edit, &TextEdit::textChanged, this, &MainWindow::on_edit_textChanged);
    

    (TextEdit is a class that inherits from QTextEdit)
    But it gives this error:

    Signal and slot arguments are not compatible.
    

    I've read some other topics online and I don't know how to solve this.
    The slot has the same arguments, as this says, it does not go with any argument.

    void on_edit_textChanged();
    

    This is the slot in the MainWindow.h file.
    I also tried to put an argument in case that it was the problem but it didn't solve nothing.
    Can you explain me why is it giving error and how to solve it?

    1 Reply Last reply
    0
    • mrjjM mrjj

      @HenkCoder

      Hmm, tried Qt 6.1.3 and code from link.
      Still compiles fine so try a completely clean build.

      H Offline
      H Offline
      HenkCoder
      wrote on last edited by
      #8

      @mrjj hey, I found out that the problem was actually this:

      connect(toUpper, &QAction::triggered, this, &MainWindow::toUpper);
      

      And it says:

      Func1 = void (QAction::*)(bool); Func2 = void (MainWindow::*)(QAction*);
      

      Meaning that triggered and toUpper arguments are not identical.
      So I just changed toUpper function arguments from QAction * to bool checked
      But I have another strange thing.
      The signals and slots connect correctly but in the application output there is:

      qt.core.qmetaobject.connectslotsbyname: QMetaObject::connectSlotsByName: No matching signal for on_edit_textChanged()
      

      Same for some others, not all.
      Can you tell me why it's happening?

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

        Did you overload any of those methods in your custom classes?

        "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

        H 1 Reply Last reply
        0
        • H Offline
          H Offline
          HenkCoder
          wrote on last edited by
          #3
          This post is deleted!
          1 Reply Last reply
          0
          • VRoninV VRonin

            Did you overload any of those methods in your custom classes?

            H Offline
            H Offline
            HenkCoder
            wrote on last edited by
            #4

            @VRonin No, I didn't

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

              Hi
              What Qt version ?

              It compiles fine in 5.15.2

              class TextEdit : public QTextEdit {
              
              public:
                  explicit TextEdit(QWidget* parent = nullptr) : QTextEdit(parent) {
              
                  }
              
              };
              
              ...
              
              connect(ui->textEdit, &TextEdit::textChanged, this, &MainWindow::on_edit_textChanged);
              

              I was wondering, if you did try to delete the build folder and recompile all again ?

              H 1 Reply Last reply
              0
              • mrjjM mrjj

                Hi
                What Qt version ?

                It compiles fine in 5.15.2

                class TextEdit : public QTextEdit {
                
                public:
                    explicit TextEdit(QWidget* parent = nullptr) : QTextEdit(parent) {
                
                    }
                
                };
                
                ...
                
                connect(ui->textEdit, &TextEdit::textChanged, this, &MainWindow::on_edit_textChanged);
                

                I was wondering, if you did try to delete the build folder and recompile all again ?

                H Offline
                H Offline
                HenkCoder
                wrote on last edited by HenkCoder
                #6

                @mrjj I'm using Qt 6.1, I didn't delete the build folder.
                I found the TextEdit from the third solution code here

                mrjjM 1 Reply Last reply
                0
                • H HenkCoder

                  @mrjj I'm using Qt 6.1, I didn't delete the build folder.
                  I found the TextEdit from the third solution code here

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @HenkCoder

                  Hmm, tried Qt 6.1.3 and code from link.
                  Still compiles fine so try a completely clean build.

                  H 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @HenkCoder

                    Hmm, tried Qt 6.1.3 and code from link.
                    Still compiles fine so try a completely clean build.

                    H Offline
                    H Offline
                    HenkCoder
                    wrote on last edited by
                    #8

                    @mrjj hey, I found out that the problem was actually this:

                    connect(toUpper, &QAction::triggered, this, &MainWindow::toUpper);
                    

                    And it says:

                    Func1 = void (QAction::*)(bool); Func2 = void (MainWindow::*)(QAction*);
                    

                    Meaning that triggered and toUpper arguments are not identical.
                    So I just changed toUpper function arguments from QAction * to bool checked
                    But I have another strange thing.
                    The signals and slots connect correctly but in the application output there is:

                    qt.core.qmetaobject.connectslotsbyname: QMetaObject::connectSlotsByName: No matching signal for on_edit_textChanged()
                    

                    Same for some others, not all.
                    Can you tell me why it's happening?

                    mrjjM 1 Reply Last reply
                    0
                    • H HenkCoder

                      @mrjj hey, I found out that the problem was actually this:

                      connect(toUpper, &QAction::triggered, this, &MainWindow::toUpper);
                      

                      And it says:

                      Func1 = void (QAction::*)(bool); Func2 = void (MainWindow::*)(QAction*);
                      

                      Meaning that triggered and toUpper arguments are not identical.
                      So I just changed toUpper function arguments from QAction * to bool checked
                      But I have another strange thing.
                      The signals and slots connect correctly but in the application output there is:

                      qt.core.qmetaobject.connectslotsbyname: QMetaObject::connectSlotsByName: No matching signal for on_edit_textChanged()
                      

                      Same for some others, not all.
                      Can you tell me why it's happening?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #9

                      Hi
                      Good you found out.

                      The : QMetaObject::connectSlotsByName: is called inside the setupUI and is part of the auto connect feature.

                      Since your slot name (on_edit_textChanged) follows the auto connect naming rule it
                      tried to match up to a widget called "edit" and didn't find one / or it didn't have a signal to match.

                      To avoid this, simply name your slot slightly differently.

                      Note: its far better to use connect statement than to rely on auto connect as it breaks so easy if you rename widgets etc.

                      So doing it right. Just use OnTextChange or similar naming

                      H 1 Reply Last reply
                      1
                      • mrjjM mrjj

                        Hi
                        Good you found out.

                        The : QMetaObject::connectSlotsByName: is called inside the setupUI and is part of the auto connect feature.

                        Since your slot name (on_edit_textChanged) follows the auto connect naming rule it
                        tried to match up to a widget called "edit" and didn't find one / or it didn't have a signal to match.

                        To avoid this, simply name your slot slightly differently.

                        Note: its far better to use connect statement than to rely on auto connect as it breaks so easy if you rename widgets etc.

                        So doing it right. Just use OnTextChange or similar naming

                        H Offline
                        H Offline
                        HenkCoder
                        wrote on last edited by
                        #10

                        @mrjj ohh ok, thank you very much.

                        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
                        • Unsolved