PDA

View Full Version : QT and C++ class problem



ricardochamie
30th January 2011, 02:55
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


widget.cpp:4: error: default argument given for parameter 4 of 'Widget::Widget(const QString&, const QString&, const QString&, QWidget*)'
widget.h:16: error: after previous specification in 'Widget::Widget(const QString&, const QString&, const QString&, QWidget*)'




My widget.h code


#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QString>

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
Q_OBJECT

public:
explicit Widget(const QString &button_nome, const QString &button_potencia, const QString &button_count, QWidget *parent = 0); //here is the problem
~Widget();

private:
Ui::Widget *ui;

private slots:
void ContaClick();

};

#endif // WIDGET_H



My widget.cpp code


#include "widget.h"
#include "ui_widget.h"

Widget::Widget(const QString &button_nome, const QString &button_potencia, const QString &button_count, QWidget *parent = 0) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);

ui->button_name->setFixedSize(121,61);
ui->button_name->setText(button_nome);
ui->label_count->setText(button_count);
ui->label_Pot_kW->setText(button_potencia);

connect (ui->button_name,SIGNAL(clicked()),this,SLOT(ContaClick ()));
}

Widget::~Widget()
{
delete ui;
}


void Widget::ContaClick() {

int i = ui->label_count->text().toInt(); //transforma o label em um inteiro "i"
i++; // incrementa o inteiro "i" em uma unidade
ui->label_count->setNum(i); //atribui ao label o valor de "i"

aamer4yu
30th January 2011, 05:04
You dont have to give the default values in .cpp file.
You just give them in declaration.


Widget::Widget(const QString &button_nome, const QString &button_potencia, const QString &button_count, QWidget *parent /*= 0 */) :
QWidget(parent),
ui(new Ui::Widget)

tbscope
30th January 2011, 05:04
Delete the "= 0" from the implementation

Doh, too late :-)

wysota
30th January 2011, 09:12
And remove the "explicit" keyword, it's not needed for constructors with more than one parameter.

ricardochamie
30th January 2011, 14:45
Thank you very much! The problem is now solved! :D