Customizing QPushButton
-
I'm attempting to make my own PushButton, but am having some issues with my constructor. I assume it's a very simple issue, but at the moment I can't think of what I'm doing wrong. My class is extremely simple at this point.
@
#ifndef PPUSHBUTTON_H
#define PPUSHBUTTON_H#include <QPushButton>
class PPushButton : public QPushButton
{Q_OBJECT
public:
explicit PPushButton(QWidget* parent = 0) : QPushButton(parent) {} ~PPushButton();
void released();
};
#endif // PPUSHBUTTON_H
My errors are:
/jrd/qtstresstest-build-desktop/mainwindow.o:: In function
PPushButton': /jrd/qtstresstest-build-desktop/../qtstresstest/ppushbutton.h:11: error: undefined reference to
vtable for PPushButton'
/jrd/qtstresstest-build-desktop/../qtstresstest/ppushbutton.h:11: error: undefined reference to `vtable for PPushButton'
:: error: collect2: ld returned 1 exit status
@Any help would be much appreciated!
EDIT: added @-tags for code formatting, Gerolf
-
You must implement the constructor in a .cpp file, not the header file. See "C++ FAQ 23.10":http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.10 for an explanation.
Also, you must implement the destructor and the method.
-
I seem to be getting the same issues.
in ppushbutton.h
@
#ifndef PPUSHBUTTON_H
#define PPUSHBUTTON_H#include <QPushButton>
class PPushButton : public QPushButton
{
Q_OBJECT
public:
explicit PPushButton(QWidget* parent = 0);
virtual ~PPushButton();
void released();
};#endif // PPUSHBUTTON_H
@in ppushbutton.cpp:
@
#include "ppushbutton.h"
#include <iostream>
using std::cout;
using std::endl;
PPushButton::PPushButton(QWidget *parent) : QPushButton(parent)
{
cout << "in ctor" << endl;
}PPushButton::~PPushButton()
{
cout << "in dtor" << endl;
}void PPushButton::released()
{
std::cout << "released" << std::endl;
}
@ -
You seem or you do?
Did you add your new .cpp file to the project and rebuild everything?@
make clean
qmake
make
@Or call rebuild in Qt Creator or your favorite IDE.
-
Delete the whole qtstresstest-build-desktop folder and recompile.