Search code examples
c++qtqpainter

error: class has no member named ‘show’


.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();
}

Error:

:~/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

Solution

  • Not really sure why you are searching for resize and show as they are not member functions of QQuickPaintedItem

    If you are interested in resizing then use code below.. Use QSize to define size and use setContentsSize to set it.

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

    Alternatively, you can use resetHeight() and resetWidth()