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: multiple definition of `MemberExists::on_viewMemberBtn_clicked()'
Forum Updated to NodeBB v4.3 + New Features

error: multiple definition of `MemberExists::on_viewMemberBtn_clicked()'

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.6k Views 2 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.
  • W Offline
    W Offline
    WhatIf
    wrote on last edited by
    #1

    I don't seem to find what is causing this error but here is what I was trying to get done.

    Create a signal/slot and connect them between MainWindow.cpp (main window) and MemberExists.cpp (QDialog).

    The error is inside moc_memberexists.cpp, I didn't write this file so I can only guess. SIGNAL 1 seems to be the one causing the problem

    // SIGNAL 0
    void MemberExists::displayExistingMember()
    {
        QMetaObject::activate(this, &staticMetaObject, 0, Q_NULLPTR);
    }
    
    // SIGNAL 1
    void MemberExists::on_viewMemberBtn_clicked()
    {
        QMetaObject::activate(this, &staticMetaObject, 1, Q_NULLPTR);
    }
    

    I looked online and the one solution I found was that the header file might have been included in multiple places. When I commented out the #include "memberexists.h" in mainWindow.cpp, I got the following error:

    error: 'MemberExists' was not declared in this scope
    MemberExists memExists;
    ^

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Somehow you mixed up signals and slots in your MemberExists class.

      The signature void MemberExists::on_viewMemberBtn_clicked() looks like the automatically generated slot when you use the "go to slot" feature in the designer. It should put a declaration like this in your MemberExists.h file:

      private slots:
          void on_viewMemberBtn_clicked();
      

      On the other hand the comment seems to indicate that it's an automatically generated body of a signal which means you have a declaration like this:

      signals:
          void on_viewMemberBtn_clicked();
      

      Maybe you or someone else edited the header and the slot fell into signals section.
      Anyway, to fix this put the declaration in the header in the private slots: section.

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

        Hi,

        on_viewMemberBtn_clicked should be a slot, did you declare it as a signal and implemented it in your class ?

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

        1 Reply Last reply
        0
        • W Offline
          W Offline
          WhatIf
          wrote on last edited by
          #4

          Is this a bug in Qt Designer? Or just me?

          I'm the only one working on this project and I use the designer.....I didn't input the viewMemberBtn manually. I right clicked on the button and choose go to, etc.

          I also tried the following and it worked but need your input if this is another way to fix the problem or it could be a new problem to introduce.

          I commented out the following section which was causing the errors in the moc_memberexists.cpp:

          /*
          // SIGNAL 1
          void MemberExists::on_viewMemberBtn_clicked()
          {
          QMetaObject::activate(this, &staticMetaObject, 1, Q_NULLPTR);
          }
          */

          the program compiled and ran fine and the part that uses the signal/slot and the button, viewMemberBtn, worked fine and produced the correct result.

          Note: when I tried the above I didn't change

          signals:
          void on_viewMemberBtn_clicked();

          to

          private slots:
          void on_viewMemberBtn_clicked();

          1 Reply Last reply
          0
          • Chris KawaC Online
            Chris KawaC Online
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by Chris Kawa
            #5

            This is a bug in your code, not in Qt. A really ugly bug I might add.

            Your solution seems to "work" because signals and slots are just regular c++ functions, so whether they are in signals or slots section you can connect to them. That is as long as there's only one implementation of it. When you use the "go to slot" function it creates an implementation in your cpp file. When you then move it to signals section it creates another implementation in the moc_* file. That won't compile. You commented out one of the definitions so it compiled. But the moc_* file will be regenerated next time you touch the ui in the designer so your workaround will be gone and it will again stop to work.

            Don't lie to your tools. Don't put slots in signals sections and then look for workarounds. That's just bad.
            The only valid solution is to put on_viewMemberBtn_clicked() in the slots section where it belongs. It is a slot, so putting it in signals section just confuses the tooling and is a clear bug on your side.

            1 Reply Last reply
            2

            • Login

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