PDA

View Full Version : error: C2664: 'myPushButton::myPushButton(const myPushButton &)': cannot convert arg



davidm71
27th June 2020, 20:33
Hi,

Trying to override a QPushbutton with my own custom class. This qpushbutton belongs to a qwidget that I have overrided in UI editor. The problem is I am getting an error. Here are the classes:

Mytitlebar class that has children qpushbuttons:

#ifndef MYTITLEBAR_H
#define MYTITLEBAR_H

#include <QWidget>

class myTitleBar : public QWidget
{
Q_OBJECT
public:
explicit myTitleBar(QWidget *parent = 0);

protected:
void paintEvent(QPaintEvent *);
void mouseDoubleClickEvent( QMouseEvent * e );


signals:
void toggleViewSignal();

public slots:
};

#endif // MYTITLEBAR_H

#include "mytitlebar.h"
#include <QStyleOption>
#include <QPainter>
#include <QDebug>
#include <QMouseEvent>




myTitleBar::myTitleBar(QWidget *parent) : QWidget(parent)
{
//this->setStyleSheet("QWidget {color:white; background: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1 stop:0 rgba(170, 0, 0, 255), stop:1 rgba(0, 0, 0, 255)); padding-bottom:5px;} ");



}

void myTitleBar::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

void myTitleBar::mouseDoubleClickEvent(QMouseEvent * e )
{
if ( e->button() == Qt::LeftButton )
{
qDebug() << "double click pressed";

emit toggleViewSignal();

}
}


And the extended pushbutton class thats giving an error:

#ifndef MYPUSHBUTTON_H
#define MYPUSHBUTTON_H

#include <QPushButton>
#include "mytitlebar.h"

class myPushButton : public QPushButton
{

Q_OBJECT
public:

explicit myPushButton(QPushButton *parent = 0);


protected:

void focusInEvent(QFocusEvent *e) override;
};

#endif // MYPUSHBUTTON_H
#include "mypushbutton.h"
#include "mytitlebar.h"
#include <QDebug>

myPushButton::myPushButton(QPushButton *parent):QPushButton(parent)
{

}

void myPushButton::focusInEvent(QFocusEvent *e)
{
qDebug() << "focus pushbutton pressed";
}


Not sure why it errors out when compiled?

Thanks

ChristianEhrlicher
28th June 2020, 09:50
In which line does the error occour?
And please use the code - tags in your post to make reading your code easier.

d_stranz
28th June 2020, 15:28
Not sure why it errors out when compiled?

Somewhere you are probably using "myPushButton" when you should be using "myPushButton *". This error occurs because even though you haven't defined a copy constructor for myPushButton, the compiler is automatically creating one for you. Qt explicitly forbids copying or assigning QObject instances, so you can't have code like



QWidget widget1;
QWidget widget2 = widget1; // invokes a copy constructor - not allowed
QWidget widget3;

widget1 = widget3; // invokes an assignment operator - not allowed


Your compiler should tell you the exact line in your code where this error occurs. Read the compiler output.