Creating classes
-
Hi,
I created a myDelegate class using File->NewFile->C++ class.
It created the following 2 files:
mydelegate.h:#ifndef MYDELEGATE_H #define MYDELEGATE_H #include <QObject> #include <QWidget> class myDelegate : public QItemDelegate { public: myDelegate(); }; #endif // MYDELEGATE_H
and mydelegate.cpp:
#include "mydelegate.h" myDelegate::myDelegate() { }
When I run build I keep getting the following error message:
C:\Programming\Projects\Folkfriends_1_0\mydelegate.h:8: error: expected class-name before '{' token
{
^
What did I miss?
Thank you. -
Hi,
I created a myDelegate class using File->NewFile->C++ class.
It created the following 2 files:
mydelegate.h:#ifndef MYDELEGATE_H #define MYDELEGATE_H #include <QObject> #include <QWidget> class myDelegate : public QItemDelegate { public: myDelegate(); }; #endif // MYDELEGATE_H
and mydelegate.cpp:
#include "mydelegate.h" myDelegate::myDelegate() { }
When I run build I keep getting the following error message:
C:\Programming\Projects\Folkfriends_1_0\mydelegate.h:8: error: expected class-name before '{' token
{
^
What did I miss?
Thank you. -
You are also missing
Q_OBJECT
and the parent in the constructor. On top of that in Qt5 QItemDelegate is deprecated, use QStyledItemDelagate insteadmydelegate.h:
#ifndef MYDELEGATE_H #define MYDELEGATE_H #include <QStyledItemDelegate> class myDelegate : public QStyledItemDelegate { Q_OBJECT public: explicit myDelegate(QObject* parent = nullptr); virtual ~myDelegate(); /* if there is the remote chance of your delegate becoming base class for another delegate save yourselves hours of debug for memory leaks and just declare a virtual destructor */ }; #endif // MYDELEGATE_H
mydelegate.cpp:
#include "mydelegate.h" myDelegate::myDelegate(QObject* parent) :QStyledItemDelegate(parent) { } myDelegate::~myDelegate(){ }
-
You are also missing
Q_OBJECT
and the parent in the constructor. On top of that in Qt5 QItemDelegate is deprecated, use QStyledItemDelagate insteadmydelegate.h:
#ifndef MYDELEGATE_H #define MYDELEGATE_H #include <QStyledItemDelegate> class myDelegate : public QStyledItemDelegate { Q_OBJECT public: explicit myDelegate(QObject* parent = nullptr); virtual ~myDelegate(); /* if there is the remote chance of your delegate becoming base class for another delegate save yourselves hours of debug for memory leaks and just declare a virtual destructor */ }; #endif // MYDELEGATE_H
mydelegate.cpp:
#include "mydelegate.h" myDelegate::myDelegate(QObject* parent) :QStyledItemDelegate(parent) { } myDelegate::~myDelegate(){ }
-
The last error message was fixed by adding a ; after class myDelegate in mydelegate.h:
class myDelegate;
In return I got new error messages:
C:\Programming\Projects\Folkfriends_1_0\mydelegate.cpp:3: error: undefined reference to `vtable for myDelegate'
collect2.exe:-1: error: error: ld returned 1 exit status -
The last error message was fixed by adding a ; after class myDelegate in mydelegate.h:
class myDelegate;
In return I got new error messages:
C:\Programming\Projects\Folkfriends_1_0\mydelegate.cpp:3: error: undefined reference to `vtable for myDelegate'
collect2.exe:-1: error: error: ld returned 1 exit status@gabor53 said in Creating classes:
table for myDelegate'
Clean All
Run qmake from the build menu.
Build allShould cure it
-
@gabor53 said in Creating classes:
table for myDelegate'
Clean All
Run qmake from the build menu.
Build allShould cure it