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. call to non static member function without an object argument
Forum Updated to NodeBB v4.3 + New Features

call to non static member function without an object argument

Scheduled Pinned Locked Moved Unsolved General and Desktop
23 Posts 10 Posters 13.1k Views 4 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.
  • C Offline
    C Offline
    Chaki
    wrote on 12 Nov 2020, 19:59 last edited by Chaki 11 Dec 2020, 20:03
    #1

    Hello everyone,
    I am trying to implement Signal&Slots. But I am getting the Error: "call to non static member function without an object argument "

    mainwindow.cpp

    void MainWindow::on_Button_clicked()
    {
        addressEntry *name = new addressEntry();
        name->setName(ui->lineName->text());
    
        connect(addressEntry::setName(name), SIGNAL(entry(QString)), addressReaderWriter::Write(name), SLOT(Write(QString)));
      
    }
    

    addressEntry.cpp

    void addressEntry::setName(QString name)
    {
        mName = name;
        qDebug() << "setName";
        emit entry(name);
    }
    
    QString addressEntry::getName()
    {
        return mName;
    }
    
    

    addressReaderWriter.cpp

    void addressReaderWriter::Write(QString name){
              name.getName();    
    }
    

    Hope Someone can help.

    1 Reply Last reply
    1
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 12 Nov 2020, 20:20 last edited by
      #2

      Hi,

      Your connect statement is wrong.

      setName is a member function that you are calling like if it was a static function.

      The first and third parameters of connect should be objects.

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

      C 1 Reply Last reply 12 Nov 2020, 20:24
      1
      • S SGaist
        12 Nov 2020, 20:20

        Hi,

        Your connect statement is wrong.

        setName is a member function that you are calling like if it was a static function.

        The first and third parameters of connect should be objects.

        C Offline
        C Offline
        Chaki
        wrote on 12 Nov 2020, 20:24 last edited by Chaki 11 Dec 2020, 20:27
        #3

        @SGaist Thank you for your reply. I understand the problem, but could you tell me how I can solve it?
        My goal is it to transfer the variable "name->setName(ui->lineName->text());"from void MainWindow::on_btnAdd_clicked() to void addressReaderWriter::Write(QString name){
        by using Signal&Slots

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 12 Nov 2020, 20:27 last edited by
          #4

          Dis you read the documentation of the method ?

          The first parameter shall be the object that will emit the signal and the third the object that will have the slot activated.

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

          C 1 Reply Last reply 12 Nov 2020, 20:38
          2
          • S SGaist
            12 Nov 2020, 20:27

            Dis you read the documentation of the method ?

            The first parameter shall be the object that will emit the signal and the third the object that will have the slot activated.

            C Offline
            C Offline
            Chaki
            wrote on 12 Nov 2020, 20:38 last edited by
            #5

            @SGaist Yes I read it, but I am having trouble to implement it correctly

            P J 2 Replies Last reply 12 Nov 2020, 23:59
            0
            • C Chaki
              12 Nov 2020, 20:38

              @SGaist Yes I read it, but I am having trouble to implement it correctly

              P Offline
              P Offline
              Pl45m4
              wrote on 12 Nov 2020, 23:59 last edited by Pl45m4
              #6

              @Chaki

              The first and third parameter needs to be a pointer to your sender / receiver object.
              What you did can not work and I also think you've put it in the wrong place.


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              0
              • C Chaki
                12 Nov 2020, 20:38

                @SGaist Yes I read it, but I am having trouble to implement it correctly

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 13 Nov 2020, 05:25 last edited by
                #7

                @Chaki said in call to non static member function without an object argument:

                but I am having trouble to implement it correctly

                Then please show what you have now...

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

                C 1 Reply Last reply 13 Nov 2020, 07:23
                0
                • J jsulm
                  13 Nov 2020, 05:25

                  @Chaki said in call to non static member function without an object argument:

                  but I am having trouble to implement it correctly

                  Then please show what you have now...

                  C Offline
                  C Offline
                  Chaki
                  wrote on 13 Nov 2020, 07:23 last edited by
                  #8

                  @jsulm currently I am trying:

                  mainwindow.cpp:

                  void MainWindow::on_btnAdd_clicked()
                  {
                      addressEntry *name = new addressEntry();
                      name->**setName**(ui->lineEdit->text());
                  
                      
                      connect(&name, SIGNAL(addressEntry::entry(QString)), addressReaderWriter::Write(name), SLOT(addressReaderWriter::Write(QString)));
                  
                    
                  }
                  

                  addressentry.h:

                  signals:
                      void entry(QString name);
                  
                  

                  addressentry.cpp:

                  
                  void addressEntry::setName(QString name)
                  {
                      mName = name;
                      emit entry(name);
                  
                  }
                  
                  

                  addressReaderWriter.h:

                  public slots:
                      void Write(QString);
                  

                  addressReaderWriter.cpp

                  void addressReaderWriter::Write(QString name){
                    name.getName();
                  
                  
                       
                  }
                  
                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 13 Nov 2020, 07:35 last edited by
                    #9

                    Your signal/slot signatures in the connect() are wrong. Please read https://doc.qt.io/qt-5/signalsandslots.html before using something.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    C 1 Reply Last reply 13 Nov 2020, 07:37
                    1
                    • Christian EhrlicherC Christian Ehrlicher
                      13 Nov 2020, 07:35

                      Your signal/slot signatures in the connect() are wrong. Please read https://doc.qt.io/qt-5/signalsandslots.html before using something.

                      C Offline
                      C Offline
                      Chaki
                      wrote on 13 Nov 2020, 07:37 last edited by
                      #10

                      @Christian-Ehrlicher I know that the connect is wrong and I have read the Docu, but I am having trouble using it correctly

                      J 1 Reply Last reply 13 Nov 2020, 07:54
                      0
                      • Christian EhrlicherC Online
                        Christian EhrlicherC Online
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 13 Nov 2020, 07:45 last edited by
                        #11

                        There is so much wrong in your code I don't even know where to start. I would suggest you to start with one of the Qt examples and learn c++ - sorry.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        0
                        • C Chaki
                          13 Nov 2020, 07:37

                          @Christian-Ehrlicher I know that the connect is wrong and I have read the Docu, but I am having trouble using it correctly

                          J Offline
                          J Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on 13 Nov 2020, 07:54 last edited by jsulm
                          #12

                          @Chaki said in call to non static member function without an object argument:

                          I have read the Docu

                          If you did then why are you still doing it wrongly? Your code does not even make sence to be honest.

                          connect(name, &addressEntry::entry, addressReaderWriterInstancePtr, &addressReaderWriter::Write);
                          

                          addressReaderWriterInstancePtr would be a pointer to an instance of addressReaderWriter which you want to react on the signal.

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

                          1 Reply Last reply
                          7
                          • Christian EhrlicherC Online
                            Christian EhrlicherC Online
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on 13 Nov 2020, 08:21 last edited by
                            #13

                            @MalitheBIG said in call to non static member function without an object argument:

                            Thats not how you treat new useres who try to get into QT.

                            Before you learn Qt you have to learn c++, thats the reality - sorry.

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            1 Reply Last reply
                            3
                            • M Offline
                              M Offline
                              Mr_Kohli
                              wrote on 13 Nov 2020, 08:27 last edited by
                              #14

                              @MalitheBIG Da stimme ich Ihnen zu

                              1 Reply Last reply
                              0
                              • J Offline
                                J Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on 13 Nov 2020, 08:28 last edited by
                                #15

                                @MalitheBIG said in call to non static member function without an object argument:

                                NUR WEIL DU EHRLICH

                                Bitte nicht persöhnlich werden...

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

                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  Mr_Kohli
                                  wrote on 13 Nov 2020, 08:29 last edited by
                                  #16

                                  @MalitheBIG That's true, maybe try and help him instead of just calling him stupid

                                  Christian EhrlicherC 1 Reply Last reply 13 Nov 2020, 08:31
                                  1
                                  • M Mr_Kohli
                                    13 Nov 2020, 08:29

                                    @MalitheBIG That's true, maybe try and help him instead of just calling him stupid

                                    Christian EhrlicherC Online
                                    Christian EhrlicherC Online
                                    Christian Ehrlicher
                                    Lifetime Qt Champion
                                    wrote on 13 Nov 2020, 08:31 last edited by
                                    #17

                                    @Mr_Kohli said in call to non static member function without an object argument:

                                    instead of just calling him stupid

                                    I never did - I told him/her to learn basic c++ before starting with Qt.

                                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                    Visit the Qt Academy at https://academy.qt.io/catalog

                                    1 Reply Last reply
                                    0
                                    • J.HilkJ Offline
                                      J.HilkJ Offline
                                      J.Hilk
                                      Moderators
                                      wrote on 13 Nov 2020, 08:35 last edited by
                                      #18

                                      @MalitheBIG what are you talking about, knowing/learning c++ is not personal stuff its essential to use Qt


                                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                      Q: What's that?
                                      A: It's blue light.
                                      Q: What does it do?
                                      A: It turns blue.

                                      1 Reply Last reply
                                      2
                                      • J Offline
                                        J Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on 13 Nov 2020, 08:36 last edited by
                                        #19

                                        @MalitheBIG Qt is a C++ framework. How do you want to use Qt without knowing C++?

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

                                        1 Reply Last reply
                                        3
                                        • JonBJ Offline
                                          JonBJ Offline
                                          JonB
                                          wrote on 13 Nov 2020, 08:51 last edited by JonB
                                          #20

                                          @MalitheBIG , @Chaki
                                          In order to use Qt you do need to know C++. This forum is for helping people with Qt questions. We do try, but we are not a C++ tutorial forum. That's just how it is.

                                          There's nothing wrong with learning to program and not yet knowing C++ well enough. Nobody blames you for that. It's just that here is not the best place to ask about C++ questions, there are better, more suitable C++ learning forums out there.

                                          Having said that. The Qt connect() statement requires 4 arguments, 2 pairs of 2, as follows:

                                          connect(signallingObject, signallingMethod,
                                                  slotObject, slotMethod);
                                          
                                          • signallingObject is some object on which something happens --- like a click.
                                          • signallingMethod is a method (belonging to the signallingObject class, declared as a signals method in the .h file).
                                          • slotObject is some object which wants to know when the event happens --- like, show a message when signallingObject gets clicked.
                                          • slotMethod is a method (belonging to the slotObject class, declared as a slots method in the .h file). slotMethod should accept the parameters which signallingMethod sends.

                                          So a simple example example looks like

                                          // In, say, your `MainWindow` class
                                          connect(ui->someButton, &QPushButton::clicked,
                                                  this, &MainWindow::onButtonClicked);
                                          
                                          /*slot*/ MainWindow::onButtonClicked()
                                          {
                                              qDebug() << "Button was clicked";
                                          }
                                          

                                          The important think is that the connect() will usually look like:

                                          connect(signallingObject, &SignallingObjectClass::method,
                                                  slotObject, &SlotObjectClass::method);
                                          

                                          You would benefit hugely from taking some time to study some of the tutorial signals & slots examples out there on the web. They are better than asking people here to come up with examples. If you Google for qt5 signal slot tutorial you get several suggestions, not only in the Qt docs, which is where I would start from:
                                          https://doc.qt.io/qt-5/signalsandslots.html
                                          https://www.bogotobogo.com/Qt/Qt5_SignalsSlotsGui.php
                                          https://prognotes.net/2019/12/qt-5-signals-and-slots-tutorial/
                                          https://www.vikingsoftware.com/getting-the-most-of-signal-slot-connections/
                                          https://wiki.qt.io/New_Signal_Slot_Syntax

                                          P.S.
                                          I will strongly recommend one thing. In @Chaki's code, and in a lot of older examples on the web, the old style SIGNAL() & SLOT() macros are used for the methods. Do not do this. It might look simpler than the new style &Class::method, but it allows you to write nonsense, which gets through the compiler but doesn't work at runtime. Using the new style will only allow you to write something sensible at compile time, and if it rejects what you try it means it was not correct. The new style is covered in the https://wiki.qt.io/New_Signal_Slot_Syntax link I gave above.

                                          1 Reply Last reply
                                          8

                                          1/23

                                          12 Nov 2020, 19:59

                                          • Login

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