Qt World Summit: Register Today!

CalendarWidget sync

  • Hello!

    First of thanks to anyone who takes the time to help me out here!

    Anyway; my problem is, as i am rather fresh in qt: syncing a calendarwidget(display widget/calendar widget) to a LineEdit, meaning whatever i write in the LineEdit field should update the calendar aswell. I have somewhat solved this the other way around tho using this:

    void Myfancyprogram::on_calendarWidget_selectionChanged()

    So if i lets say load a date from a table in a database and fill out the LineEdit, how do i automaticly update the CalendarWidget aswell? And i am not asking for the database code, just if there is a way, like above to simply update the calendarwidget based upon whats in the LineEdit field?

    Much love,,

  • Lifetime Qt Champion


    You can use setSelectedData with a QDate built using the content of your QLineEdit using one of the QDate::fromString overload.

  • Alright and thank you for the tip!

    I followed your advice more or less, at least i didn't stray from my skill path :p

    Iv'e been looking at the syntax and so far i have this, please tell me if i am on the right path, and how eventually i could arrive there; if you see it.

    void Myfancyprog::on_txt_dato_textChanged(const QString &arg1)
        QString date_test;
        QDateTime date;
        date.fromString(date_test, "yyyy-MM-dd");

  • Lifetime Qt Champion

    You are missing the call to ui->calendarWidget->setSelectedDate(date);.

    Did you also ensure that you can only enter valid date in your QLineEdit ?

    By the way, why not use a QDateEdit widget ?

  • Iv'e actually tried that but it gave me a couple of errors(no matching function call, no known conversion for argument 1), however i am too much a noob to realise i was maybe onto something and moved on. And apparantly still am, any suggestions?

    And i know(believe,fairly certain(maybe)) i'm sending it in the right format, I cannot use dateedit because the data is being stored in a database in a way i cannot modify, which in turn would make it an even bigger endavour than making my problem work this way :p

  • Lifetime Qt Champion

    What exact error did you get ?

    What format is it ? How are you retrieving it ?

Log in to reply