【问题标题】:error: class has no member named ‘show’错误:类没有名为“show”的成员
【发布时间】:2014-02-01 05:38:36
【问题描述】:

.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

【问题讨论】:

  • 因为QQuickPaintedItem真的没有showresize。它不是小部件。

标签: c++ qt qpainter


【解决方案1】:

不太清楚为什么要搜索resizeshow,因为它们不是QQuickPaintedItem 的成员函数

如果您对调整大小感兴趣,请使用下面的代码.. 使用QSize定义大小,使用setContentsSize设置大小。

MyGraph g;

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

或者,您可以使用resetHeight()resetWidth()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-04
    • 2013-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多