I'm new to C++ and Qt. My problem is, that I created a new class and it doesn't get compiled. So the compiler says: "unresolved Object in ...". This is the header:
#ifndef TRANSITIOUSPLAYER_H
#define TRANSITIOUSPLAYER_H
#include <QtMultimedia>
class TransitiousPlayer
{
public:
TransitiousPlayer();
TransitiousPlayer(const TransitiousPlayer &other);
~TransitiousPlayer();
void play();
};
Q_DECLARE_METATYPE(TransitiousPlayer)
#endif // TRANSITIOUSPLAYER_H
class:
#include "transitiousplayer.h"
...
void TransitiousPlayer::play(){
QMediaPlayer* player = new QMediaPlayer(this);
QMediaPlaylist* playlist = new QMediaPlaylist(player);
playlist->playlist->addMedia(new QString("sh.mp3"));
player->setPlaylist(playlist);
player->play();
}
In mainwindow.cpp:
TransitiousPlayer player;
player.play();
In main i also call:
qRegisterMetaType<TransitiousPlayer>();
If i only try to compile transitiousplayer.cpp, it says: "Target debug/transitiousplayer.obj doesn't exist."
Probably too late to help, but I had the same issue and am also new to QT (5.2.0).
For some reason, if the makefile is already made, in my situation, it wouldn't add it to the makefile, even if you select 'Clean', which is what I assumed Clean would do.
The solution that worked for me was to manually delete the contents of the build directory and hit build again, in which case it recreates it. I am not sure what clean is supposed to do if not this.
I had a project with a couple of classes, which i built and ran, then made a new class with File->New File.. C++ class. Wrote my class and press run again. Got that my constructor was missing. Hit build on just that file and got the same Target Debug/...obj doesn't exist. Checked the pro file and the class source and header names were present, checked the disk, they were there, checked the Makefile.Debug and there was no trace of those files. Hit clean, it didn't change the makefile. Deleted the contents of the build-Projectname-Desktop-qt_5_2_0.. directory, hit run, and it built and ran without issue.
Posted for future reference: I ran into this problem after adding a new class file, to get the new file to compile you have to run qmake under the Build menu.
At Qt project view, select "run qmake" again. Then everything is O.K.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With