Results 1 to 5 of 5

Thread: QT and C++ class problem

  1. #1

    Default QT and C++ class problem

    Ok! First time here at QtCentre. Thanks in advance for the help!
    I know where my problem is... but don't know how to fix it!

    Compiler Output
    Qt Code:
    1. widget.cpp:4: error: default argument given for parameter 4 of 'Widget::Widget(const QString&, const QString&, const QString&, QWidget*)'
    2. widget.h:16: error: after previous specification in 'Widget::Widget(const QString&, const QString&, const QString&, QWidget*)'
    To copy to clipboard, switch view to plain text mode 


    My widget.h code
    Qt Code:
    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3.  
    4. #include <QWidget>
    5. #include <QString>
    6.  
    7. namespace Ui {
    8. class Widget;
    9. }
    10.  
    11. class Widget : public QWidget
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit Widget(const QString &button_nome, const QString &button_potencia, const QString &button_count, QWidget *parent = 0); //here is the problem
    17. ~Widget();
    18.  
    19. private:
    20. Ui::Widget *ui;
    21.  
    22. private slots:
    23. void ContaClick();
    24.  
    25. };
    26.  
    27. #endif // WIDGET_H
    To copy to clipboard, switch view to plain text mode 


    My widget.cpp code
    Qt Code:
    1. #include "widget.h"
    2. #include "ui_widget.h"
    3.  
    4. Widget::Widget(const QString &button_nome, const QString &button_potencia, const QString &button_count, QWidget *parent = 0) :
    5. QWidget(parent),
    6. ui(new Ui::Widget)
    7. {
    8. ui->setupUi(this);
    9.  
    10. ui->button_name->setFixedSize(121,61);
    11. ui->button_name->setText(button_nome);
    12. ui->label_count->setText(button_count);
    13. ui->label_Pot_kW->setText(button_potencia);
    14.  
    15. connect (ui->button_name,SIGNAL(clicked()),this,SLOT(ContaClick()));
    16. }
    17.  
    18. Widget::~Widget()
    19. {
    20. delete ui;
    21. }
    22.  
    23.  
    24. void Widget::ContaClick() {
    25.  
    26. int i = ui->label_count->text().toInt(); //transforma o label em um inteiro "i"
    27. i++; // incrementa o inteiro "i" em uma unidade
    28. ui->label_count->setNum(i); //atribui ao label o valor de "i"
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QT and C++ class problem

    You dont have to give the default values in .cpp file.
    You just give them in declaration.

    Qt Code:
    1. Widget::Widget(const QString &button_nome, const QString &button_potencia, const QString &button_count, QWidget *parent /*= 0 */) :
    2. QWidget(parent),
    3. ui(new Ui::Widget)
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QT and C++ class problem

    Delete the "= 0" from the implementation

    Doh, too late :-)

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QT and C++ class problem

    And remove the "explicit" keyword, it's not needed for constructors with more than one parameter.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5

    Default Re: QT and C++ class problem

    Thank you very much! The problem is now solved!
    Last edited by ricardochamie; 30th January 2011 at 14:45.
    Qt Code:
    1. ricardo chamié
    2. www.ricardochamie.com
    3. belém - pa - brasil
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 7
    Last Post: 2nd September 2010, 19:42
  2. Problem with QDialog class
    By sudheer168 in forum Qt Programming
    Replies: 4
    Last Post: 23rd December 2008, 09:03
  3. class operator problem
    By MarkoSan in forum General Programming
    Replies: 6
    Last Post: 22nd May 2008, 19:13
  4. Problem with a color class
    By zorro68 in forum Qt Programming
    Replies: 24
    Last Post: 26th September 2007, 15:30
  5. problem declaring a class
    By mickey in forum General Programming
    Replies: 1
    Last Post: 26th May 2006, 18:12

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.