Nominate our 2022 Qt Champions!

QCalendarWidget does not propagate signals

  • Hi all,

    I am trying to work with QCalendarWidget, I need to know when somebody change date...
    But it looks like that QCalendarWindget does not send signal.

    QGridLayout *mycalendarLayout = new QGridLayout();
    QCalendarWidget *calendarWidgetfrom = new QCalendarWidget();


    connect(calendarWidgetfrom, SIGNAL(selectionChanged()), this, SLOT(TestSignal()));

    connect(calendarWidgetfrom,SIGNAL(clicked(QDate)),this, SLOT(DataFromChanged));

    QWidget *myQWidget = new QWidget();
    m_toolbox->addItem(myQWidget, tr("Calendar"));

    Could you please anybody tell me, what I am doing wrong?

    Thank you!

  • Welcome to DevNet!

    Are there any messages in a console when you start your app?

    this one should complain about missing receiver or parentheses.
    connect(calendarWidgetfrom,SIGNAL(clicked(QDate)),this, SLOT(DataFromChanged));

  • YES, thank you.

    Correct version:
    @connect(calendarWidgetfrom,SIGNAL(clicked(QDate)),this, SLOT(DataFromChanged(const QDate&)));@

    Thank you!

  • I would suggest to use "new signal/slot syntax":

    It will help to avoid such errors.
    For your example
    connect(calendarWidgetfrom, &QCalendarWidget::selectionChanged, this, &Widget::TestSignal);
    connect(calendarWidgetfrom, &QCalendarWidget::clicked, this, &Widget::DataFromChanged);

Log in to reply