错误:课堂没有名为“ Show”的成员

error: class has no member named ‘show’

本文关键字:Show 成员 课堂 错误      更新时间:2023-10-16

.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

不确定为什么要搜索resizeshow,因为它们不是QQuickPaintedItem

的成员函数

如果您有兴趣调整大小,请在下面使用代码。使用QSize定义大小并使用setContentsSize将其设置。

MyGraph g;
QSize size;
size.setHeight(200);
size.setWidth(200);
g.setContentsSize(size);

另外,您可以使用resetHeight()resetWidth()