c++ - Qt/C++ 将指针指向另一个构造函数

标签 c++ qt

所以我希望有人能在以下方面再次帮助我。 我想在另一个类中使用一个类的指针。

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/

相关文章:

c++ - QFuture::resultReadyAt(int index) 索引中的索引是什么

c++ - PROCESSENTRY32 .dwSize 和 sizeof

c++ - 从字符串中删除所有空格

qt - QBoxLayout搞砸了QFormLayout?

linux - 我需要的所有依赖项

qt - OpenCV、诺基亚和 Qt - 它会工作吗?

c++ - double to std::cout 截断数据

c++ - 在 C++ 上创建结构节点

c++ - 为什么在重新扫描期间没有替换参数替换?

c++ - 无法加载qt平台插件windows