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. Error when connecting a custom class and MainWindow

Error when connecting a custom class and MainWindow

Scheduled Pinned Locked Moved Solved General and Desktop
classconnectconnect problemsignalsslots
4 Posts 3 Posters 1.1k 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.
  • F Offline
    F Offline
    Forfunckle
    wrote on 11 Jan 2020, 11:15 last edited by
    #1

    Hello, I made a class called Button and I have an object of type Button*. When I try connecting a signal of that object with a slot of MainWindow, it just says "no matching member function for call to 'connect'" and "no known conversion from 'Button *' to 'const QObject *' for 1st argument.

    Button* button = new Button();
    connect(button, SIGNAL(Button::sendDeleteSignal()), this, SLOT(checkForDeletes())); //error
    

    Note, I do not have much experience. How do I fix this? qobject_cast does not work.

    J 1 Reply Last reply 11 Jan 2020, 11:20
    0
    • F Offline
      F Offline
      Forfunckle
      wrote on 12 Jan 2020, 16:34 last edited by
      #4

      The problem was that my class inherited QGraphicsItem, not QObject, but I found another way to do what I wanted. From now on, I will use the new syntax. Thank you!

      1 Reply Last reply
      1
      • F Forfunckle
        11 Jan 2020, 11:15

        Hello, I made a class called Button and I have an object of type Button*. When I try connecting a signal of that object with a slot of MainWindow, it just says "no matching member function for call to 'connect'" and "no known conversion from 'Button *' to 'const QObject *' for 1st argument.

        Button* button = new Button();
        connect(button, SIGNAL(Button::sendDeleteSignal()), this, SLOT(checkForDeletes())); //error
        

        Note, I do not have much experience. How do I fix this? qobject_cast does not work.

        J Offline
        J Offline
        JonB
        wrote on 11 Jan 2020, 11:20 last edited by JonB 1 Nov 2020, 11:22
        #2

        @Forfunckle
        In a word, especially if you sound like you are writing new Qt code, switch to the new, compile-time-supported way of connecting signals & slots, as documented in https://doc.qt.io/qt-5/signalsandslots.html or read through https://wiki.qt.io/New_Signal_Slot_Syntax, instead of using SIGNAL() & SLOT() macros. You will get a (more) meaningful compile-time error for whatever your fault is.

        In this case, "no known conversion from 'Button *' to 'const QObject *' leads me to wonder what your Button class is? It sounds like it isn't even a QWidget....?

        1 Reply Last reply
        3
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 11 Jan 2020, 11:21 last edited by mrjj 1 Nov 2020, 11:26
          #3

          Hi
          the syntax is not correct should be
          connect(button, SIGNAL(sendDeleteSignal()), this, SLOT(checkForDeletes()));
          with no classname:: and would show paramters if it has any.

          Also
          Did you remember Q_OBJECT

          class Button : public QPushButton
          {
          Q_OBJECT

          Please show Buttons .h file

          It must also inherit from a QWidget or QObject which your error suggests you did not.

          And as @JonB says, the new syntax is far better as it helps to find errors.

          connect(button, &Button::sendDeleteSignal, this, &MainWindow::checkForDeletes);

          1 Reply Last reply
          3
          • F Offline
            F Offline
            Forfunckle
            wrote on 12 Jan 2020, 16:34 last edited by
            #4

            The problem was that my class inherited QGraphicsItem, not QObject, but I found another way to do what I wanted. From now on, I will use the new syntax. Thank you!

            1 Reply Last reply
            1

            1/4

            11 Jan 2020, 11:15

            • Login

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