QObject::connect()



  • 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



  • @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.



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



  • 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


  • Qt Champions 2016

    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]



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



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.