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 classTrack
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 variabletrackList
instead. -
Another issue, your class
Track
does not have a slot calledplay()
, there is aplaySong()
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 thestd::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 -
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]