PDA

View Full Version : signal & slot problem



ahmetturan
12th February 2012, 16:44
i created one pushbutton and label in myClass.cpp;


QLabel *lbl=new QLabel();
QPushButton *btn=new QPushButton("button");

ui->tableWidget->setCellWidget(0,0,lbl);
ui->tableWidget->setCellWidget(0,1,btn);

i want that: when i click button, calendar will open and when i click calendar, date will be written on label.
and i want to use signal & slot.

i created these functions:


myClass.h

public:
QCalendarWidget *cal;

public slots:
void writeDate(QLabel *);
void func();
void openCal();

signals:
void calClicked(QLabel *);



myClass.cpp

connect(btn,SIGNAL(clicked()),this,SLOT(openCal()) ); //it works
connect(cal,SIGNAL(clicked(QDate)),this,SLOT(func( )));//it works
myClass *a,*b;
QObject::connect(a, SIGNAL(calClicked(lbl)), b, SLOT(writeDate(lbl)));//it never works

void myClass::func()
{
emit calClicked(lbl);
}

void myClass::writeDate(QLabel *lbl)
{
cal->close();
lbl->setText(cal->selectedDate());
}


but i always get error:QObject::connect: Cannot connect (null)::calClicked(lbl) to (null)::writeDate(lbl)


sorry for my english.

Zlatomir
12th February 2012, 16:59
Make sure that a and b pointers are initialized?

//I don't really follow why you need two objects of that class? Shouldn't the functionality you talk about happen inside the object? Anyway this might be me - because i don't see the whole application code, so just check the pointers if i'm wrong with this part.

LE: also the connect syntax is incorrect, if should be QLabel* instead of lbl. //you pass lbl when you emit the signal - at the connect you say only the parameter type.