i created one pushbutton and label in myClass.cpp;
ui->tableWidget->setCellWidget(0,0,lbl);
ui->tableWidget->setCellWidget(0,1,btn);
QLabel *lbl=new QLabel();
QPushButton *btn=new QPushButton("button");
ui->tableWidget->setCellWidget(0,0,lbl);
ui->tableWidget->setCellWidget(0,1,btn);
To copy to clipboard, switch view to plain text mode
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:
public slots:
void func();
void openCal();
signals:
myClass.h
public:
QCalendarWidget *cal;
public slots:
void writeDate(QLabel *);
void func();
void openCal();
signals:
void calClicked(QLabel *);
To copy to clipboard, switch view to plain text mode
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());
}
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());
}
To copy to clipboard, switch view to plain text mode
but i always get error:QObject::connect: Cannot connect (null)::calClicked(lbl) to (null)::writeDate(lbl)
sorry for my english.
Bookmarks