所以我希望有人能在以下方面再次帮助我。 我想在另一个类中使用一个类的指针。
car.h
class wheel;
class car : public QMainWindow
{
public:
car (QWidget *parent = 0);
wheel *test;
};
class wheel : QGraphicsPixmapItem
{
public:
wheel();
void hoverEnterEvent (QGraphicsSceneHoverEvent*);
};
car.cpp
#include "car.h"
wheel::wheel()
{
}
car::car (QWidget*)
{
test = new wheel;
test -> setAcceptHoverEvents (true);
}
wheel::hoverEnterEvent (QGraphicsSceneHoverEvent*)
{
test -> setPixmap (/*thePixmap*/);
}
问题是,我不能在 class wheel 中使用指针“test”, 我真的不知道如何在“不”使指针“测试”全局的情况下做到这一点。
最佳答案
wheel::hoverEnterEvent
是 wheel 类的一部分。它不需要指向自身的指针来对自身进行操作,因此只需替换
test -> setPixmap (/*thePixmap*/);
与
setPixmap (/*thePixmap*/);
关于c++ - Qt/C++ 将指针指向另一个构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11547305/