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();
    calendarWidgetfrom->setMinimumDate(QDate(2014,1,1));
    calendarWidgetfrom->setMaximumDate(QDate(2028,1,1));

    calendarWidgetfrom->setSelectionMode(QCalendarWidget::SelectionMode::SingleSelection);
    mycalendarLayout->addWidget(calendarWidgetfrom,0,0,Qt::AlignCenter);

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

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

    QWidget *myQWidget = new QWidget();
    myQWidget->setLayout(mycalendarLayout);
    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":http://qt-project.org/wiki/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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.