Results 1 to 3 of 3

Thread: error: C2664: 'myPushButton::myPushButton(const myPushButton &)': cannot convert arg

  1. #1
    Join Date
    Apr 2017
    Posts
    21
    Qt products
    Qt5
    Platforms
    Windows

    Default error: C2664: 'myPushButton::myPushButton(const myPushButton &)': cannot convert arg

    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(spreadad, 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:aintEvent(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

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    496
    Thanked 73 Times in 69 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error: C2664: 'myPushButton::myPushButton(const myPushButton &)': cannot convert

    In which line does the error occour?
    And please use the code - tags in your post to make reading your code easier.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,532
    Thanks
    253
    Thanked 723 Times in 713 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: error: C2664: 'myPushButton::myPushButton(const myPushButton &)': cannot convert

    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

    Qt Code:
    1. QWidget widget1;
    2. QWidget widget2 = widget1; // invokes a copy constructor - not allowed
    3. QWidget widget3;
    4.  
    5. widget1 = widget3; // invokes an assignment operator - not allowed
    To copy to clipboard, switch view to plain text mode 

    Your compiler should tell you the exact line in your code where this error occurs. Read the compiler output.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Convert INT to const wchat_t or LPWSTR
    By SirJonas in forum General Programming
    Replies: 1
    Last Post: 22nd March 2017, 19:24
  2. Replies: 0
    Last Post: 22nd June 2013, 10:02
  3. Replies: 2
    Last Post: 15th December 2012, 17:58
  4. How to convert string into const int ?
    By babygal in forum Qt Programming
    Replies: 3
    Last Post: 16th July 2010, 10:57
  5. Replies: 1
    Last Post: 4th December 2009, 17:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.