.h
#include <QtQuick/QQuickPaintedItem>
#include <QColor>
#include <QLineF>
#include <QMutex>
class MyGraph : public QQuickPaintedItem
{
Q_OBJECT
protected:
virtual void componentComplete();
public:
MyGraph (QQuickPaintedItem *parent = 0);
void paint (QPainter *painter);
};.cpp
#include <QApplication>
#include <iostream>
#include <QPen>
#include "qpainter.h"
#include <QtQml/qqmlengine.h>
#include "graph.h"
MyGraph :: MyGraph (QQuickPaintedItem *parent) : QQuickPaintedItem (parent) {}
void MyGraph :: paint (QPainter *painter)
{
}
void MyGraph::componentComplete ()
{
QQuickPaintedItem::componentComplete ();
}
int main(int argc, char **argv)
{
QApplication app (argc, argv);
MyGraph g;
g.resize(200, 200);
g.show()
return app.exec();
}误差
:~/myQtGraph$ make
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_QUICK_LIB -DQT_QML_LIB -DQT_WIDGETS_LIB -DQT_NETWORK_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/opt/Qt5.1.0/5.1.0/gcc_64/mkspecs/linux-g++ -I. -I. -I/opt/Qt5.1.0/5.1.0/gcc_64/include -I/opt/Qt5.1.0/5.1.0/gcc_64/include/QtQuick -I/opt/Qt5.1.0/5.1.0/gcc_64/include/QtQml -I/opt/Qt5.1.0/5.1.0/gcc_64/include/QtWidgets -I/opt/Qt5.1.0/5.1.0/gcc_64/include/QtNetwork -I/opt/Qt5.1.0/5.1.0/gcc_64/include/QtGui -I/opt/Qt5.1.0/5.1.0/gcc_64/include/QtCore -I. -o graph.o graph.cpp
graph.cpp:11:6: warning: unused parameter ‘painter’ [-Wunused-parameter]
graph.cpp: In function ‘int main(int, char**)’:
graph.cpp:26:5: error: ‘class MyGraph’ has no member named ‘resize’
graph.cpp:27:5: error: ‘class MyGraph’ has no member named ‘show’
make: *** [graph.o] Error 1发布于 2014-02-01 06:10:26
不太清楚为什么要搜索resize和show,因为它们不是QQuickPaintedItem的成员函数
如果您对调整大小感兴趣,请使用下面的代码。使用QSize定义大小,并使用setContentsSize设置大小。
MyGraph g;
QSize size;
size.setHeight(200);
size.setWidth(200);
g.setContentsSize(size);或者,您可以使用resetHeight()和resetWidth()。
https://stackoverflow.com/questions/21494567
复制相似问题