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. QObject::connect()
QtWS25 Last Chance

QObject::connect()

Scheduled Pinned Locked Moved Unsolved General and Desktop
connectconnect failureqt5.5.0qobject
6 Posts 3 Posters 3.2k 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.
  • L Offline
    L Offline
    Lorence
    wrote on last edited by
    #1

    why cant i get rid of this error?

    error: no matching function for call to 'MainWindow::connect(PlayList*&, const char*, __gnu_cxx::__alloc_traits<std::allocator<Track> >::value_type*, const char*)'
    QObject::connect(ui->tab1List,SIGNAL(clickedToPlay()),&playList[playList.size()-1],SLOT(play()));
    ^
    heres my code:
    http://pastebin.com/4cpKTYSB

    1 Reply Last reply
    0
    • TheBadgerT Offline
      TheBadgerT Offline
      TheBadger
      wrote on last edited by TheBadger
      #2

      @Lorence
      From your code class Track does not derive from QObject, thus you can not connect to it:

      class Track : public QObject 
      {
          Q_OBJECT
          ...
      };
      

      Edit:
      Also the following looks strange:

      std::vector<Track> playList;
      

      Since you have a class called PlayList. If that is correct I suggest calling your variable trackList instead.


      Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

      1 Reply Last reply
      0
      • TheBadgerT Offline
        TheBadgerT Offline
        TheBadger
        wrote on last edited by
        #3

        Another issue, your class Track does not have a slot called play(), there is a playSong() that I suspect you wanted to call.

        If you are using Qt 5 use the new connect syntax instead and you will reduce such errors:

        connect(ui->tab1List, &PlayList::clickedToPlay, &playList.back(), &Track::playSong);
        

        PS: I replaced the playList[playList.size()-1] with the std::vector::back() function call since it should do the same but the intent is clear.


        Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

        L 1 Reply Last reply
        0
        • L Offline
          L Offline
          Lorence
          wrote on last edited by
          #4

          Guys!!! sorry for the late reply, i was so busy from my school projects

          heres the error:
          error: use of deleted function 'Track::Track(const Track&)'
          { ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
          ^

          heres the new code:
          http://pastebin.com/PgR8bUeg

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

            hi
            you have declared your list as using non pointers.
            std::vector<Track> playList;
            So track must be copy able.
            but since its a QObject, its not allowed.
            So it must be
            std::vector<Track*> playList;

            Thats why you get Track(const Track&) error

            [edit: fixed typo -> QObject are not copyable SGaist]

            1 Reply Last reply
            1
            • TheBadgerT TheBadger

              Another issue, your class Track does not have a slot called play(), there is a playSong() that I suspect you wanted to call.

              If you are using Qt 5 use the new connect syntax instead and you will reduce such errors:

              connect(ui->tab1List, &PlayList::clickedToPlay, &playList.back(), &Track::playSong);
              

              PS: I replaced the playList[playList.size()-1] with the std::vector::back() function call since it should do the same but the intent is clear.

              L Offline
              L Offline
              Lorence
              wrote on last edited by Lorence
              #6

              @TheBadger
              I tried to investigate the error, and i found where it is coming from
              its from this line
              playList.emplace_back(ui->song->text().toStdString());
              which is written before the connect() in the code

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