Reputation: 531
I am getting the following error when trying to build my app in Qt Creator:
error (line 3): no matching function for call to ‘QGraphicsScene::QGraphicsScene()’
The source for this is simply (file name is gamscene.cpp):
#include "gamescene.h"
GameScene::GameScene() : QGraphicsScene(parent)
{
}
I have googled around and have seen some similar issues but I don't really understand the answers given.
Upvotes: 1
Views: 1964
Reputation: 324
We've derived from the QGraphicsScene class like so
class ImprintTemplateScene : public QGraphicsScene
{
Q_OBJECT
public:
ImprintTemplateScene(QObject *parent = 0);
...
};
Notice the parent is a parameter passed to the constructor. The constructor implementation looks like:
ImprintTemplateScene::ImprintTemplateScene(QObject *parent)
: QGraphicsScene(parent),
sceneMode(mode_normal),
editingTextBox(0)
{
}
Upvotes: 2
Reputation: 13946
parent
on your line 3 has to come from somewhere. Since you are defining a GameScene
constructor, presumably it's really an argument to the constructor (I'm not familiar with Qt so I don't know what type parent
should be -- use the appropriate type in your actual code):
GameScene::GameScene(TypeOfParent parent) : QGraphicsScene(parent)
{
}
Or if it can make sense for the QGraphicsScene
constructor to be called without a parent, then:
GameScene::GameScene() : QGraphicsScene()
{
}
might be a possibility. Probably not, since the error message indicates that there are no zero-argument constructors of QGraphicsScene
.
Also, you didn't post the class definition, but given your constructor definition attempt I assume that GameScene
publicly inherits from QtGraphicsScene
. So when you are constructing GameScene
you need to call the superclass constructor (as you are attempting to do). But any arguments to the superclass constructor can only come from arguments to your constructor. So if the superclass constructor requires an argument, your constructor will need that argument so it can pass it to the superclass constructor (unless it makes sense for you to pass the superclass constructor a compile-time constant argument).
Upvotes: 0