我正在尝试制作一个QPainter
对象。所有的例子都做类似的事情。但抱怨:QT C++ QPainter - 如何正确使用'this'
X:\Folder\ink.cpp:56: error: C2664: QPainter::QPainter(QPaintDevice *) : cannot convert parameter 1 from Ink *const to QPaintDevice * Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
简化代码:
#include <QtCore>
#include <QtGui>
#include <QPainter>
class Ink
{
public:
void ink::paintEvent(QPaintEvent* event)
{
QPainter painter(this);
}
};
上线时出现错误:QPainter painter(this);
那么它也抱怨
X:\Folder\ink.cpp:11: error: C2653: ink : is not a class or namespace name
这是对线:
void ink::paintEvent(QPaintEvent *event)
请使用宝贝的话,我今天才开始用C++。
如果你“今天开始使用C++”,我认为你不应该直接跳到Qt的东西,你必须先学习语言的基础。这适用于任何语言,但对于C++来说却是双重的,因为它作为一种语言特别复杂。 –
我试图避免这么说,但我在想它。 –
你们可能是对的,当项目开始觉得徒劳时,我总是走10步.. :) – Vii