PDA

View Full Version : problems



IRON_MAN
9th July 2009, 13:45
I´m doing 2 buttons one disabled the other one. To do that I have done the following that:

button.h


#ifndef BUTTONS_H
#define BUTTONS_H

#include <QWidget>
#include <QBuffer>


class QPushButton;

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

private slots:
void blocked();

};

#endif

buttons.cpp


QPushButton *deshabilitar = new QPushButton(tr("deshabilitar"), this);
connect(deshabilitar, SIGNAL(clicked()),this, SLOT(blocked()));

QPushButton *Button7= new QPushButton(tr("Button7"), this);

void buttons:: blocked( )
{
Button7.setDisabled(true);
}



Why am I having problems?

nish
9th July 2009, 14:09
make Button7 a member of buttons class.

IRON_MAN
9th July 2009, 14:11
how??? I have done like this but it doesn´t work.



#include <QtGui>
#include <QPushButton>
#include <QPixmap>
#include <QIcon>

#include "buttons.h"

buttons::buttons(QWidget *parent)
: QWidget(parent)
{


QPushButton *deshabilitar = new QPushButton(tr("deshabilitar"), this);
connect(deshabilitar, SIGNAL(clicked()),this, SLOT(blocked()));

QPushButton *Button7= new QPushButton(tr("Button7"), this);

void buttons:: blocked( )
{
Button7.setDisabled(true);
}
}

nish
9th July 2009, 14:17
class buttons: public QWidget
{
Q_OBJECT
public:
buttons(QWidget *parent = 0);

private slots:
void blocked();

//LOOK HERE
QPushButton *Button7;


};

#endif

buttons.cpp

QPushButton *deshabilitar = new QPushButton(tr("deshabilitar"), this);
connect(deshabilitar, SIGNAL(clicked()),this, SLOT(blocked()));

//LOOK HERE
//QPushButton *Button7= new QPushButton(tr("Button7"), this);
Button7= new QPushButton(tr("Button7"), this);

void buttons:: blocked( )
{
//FINALLY LOOK HERE
//Button7.setDisabled(true);
Button7->setDisabled(true);
}

make other buttons the member as well

IRON_MAN
9th July 2009, 14:43
it doesn't work:(

I take these errors:


a function-definition is not allowed here before '{' token botoiak.cpp btns 140 C/C++ Problem
make: *** [debug] Error 2 btns 0 C/C++ Problem
make[1]: *** [tmp/obj/debug_shared/botoiak.o] Error 1 btns 0 C/C++ Problem

nish
9th July 2009, 14:46
change this section to


private slots:
void blocked();

private://PUT THIS LINE
//LOOK HERE
QPushButton *Button7;

nish
9th July 2009, 14:48
hey.. are you doing all the code in the buttons contstructor?

IRON_MAN
9th July 2009, 14:56
sorry but I don't get it:

botoiak.h


#ifndef BOTOIAK_H
#define BOTOIAK_H

#include <QtGui/QWidget>

class botoiak : public QWidget
{
Q_OBJECT

public:
botoiak(QWidget *parent = 0);

private slots:
void blocked();

private:
QPushButton *Button7;

};

#endif


botoiak.cpp


#include <QtGui>
#include <QPushButton>
#include <QPixmap>
#include <QIcon>
#include <QApplication>
#include "botoiak.h"

botoiak::botoiak(QWidget *parent)
: QWidget(parent)
{

QPushButton *habilitar = new QPushButton(tr("habilitar"), this);

QPushButton *deshabilitar = new QPushButton(tr("deshabilitar"), this);
connect(deshabilitar, SIGNAL(clicked()),this, SLOT(blocked()));


Button7= new QPushButton(tr("Button7"), this);

void botoiak:: blocked( )
{
Button7->setDisabled(true);
}


// setWindowTitle(tr("Botoiak"));
//resize(400,400);
}

nish
9th July 2009, 15:00
holy cow!!! you are inserting a slot defination inside the constructor...


botoiak.cpp

#include <QtGui>
#include <QPushButton>
#include <QPixmap>
#include <QIcon>
#include <QApplication>
#include "botoiak.h"

botoiak::botoiak(QWidget *parent)
: QWidget(parent)
{

QPushButton *habilitar = new QPushButton(tr("habilitar"), this);

QPushButton *deshabilitar = new QPushButton(tr("deshabilitar"), this);
connect(deshabilitar, SIGNAL(clicked()),this, SLOT(blocked()));


Button7= new QPushButton(tr("Button7"), this);




// setWindowTitle(tr("Botoiak"));
//resize(400,400);
}

//Move it here
void botoiak:: blocked( )
{
Button7->setDisabled(true);
}

IRON_MAN
9th July 2009, 15:19
thank you!! that was my big problem. Now it works.

nish
9th July 2009, 15:27
thx to god... if you have asked one more question i would have died.

Lykurg
9th July 2009, 16:24
if you could please use the [ CODE ] tags for further post, because then one could read your code better. Second you could simply use:

connect(deshabilitar, SIGNAL(clicked(bool)), Button7, SLOT(setEnabled(bool)));
assuming you button is not checkable.