check date called from firebase against calendar?

  • Hey guys,

    I am working with QML saving Calendar selected dates into a firebase database. when i open the calendar page i am then reading the saved dates back.

    I need to check the dates from firebase to the calendar and any date saved will display a marker?

    how could i set this up? as i'm well and truly stuck XD


  • Lifetime Qt Champion

    Subclass QCalendarWidget and override
    so you can draw the marker.
    Open DB and store the "marked" date in a lookup list
    so when paintCell is called, you check the date paramter against
    the data and draw marker if needed.

  • @mrjj Thanks for getting back to be so fast! and thanks for the response!!

    I am using the QtQuick Calendar would this method still be able to be applied?

    When you say lookup list, by what do you mean(sorry if it's an obvious question?)

    my dates are stored like so, would this be the appropriate way to get it working?

    ---------date: "2018-09-03"
    ---------date: "2018-09-04"
    ---------date: "2018-09-05"

    Thanks again!

  • Lifetime Qt Champion

    oh, its QML. nope that is different.
    I think you can make your own
    if the default is not looking like you want. else default is fine.
    And also forget about the looup list. :) not needed.
    The QML calendar uses a model based SqlQueryModel so all you really need
    is change the database type and the query in
    void SqlEventModel::createConnection()
    in sample ( you linked) it just creates a table and put data in.
    you would just read the ones you have. ( SQL select statement)

  • @mrjj
    again I can't thank you enough for the help!

    I have amended my original post stating I am working in QML and added the QML tag also.

    forgive me, I am a novice but adamant to complete this project and learning unfathomable amounts along the way assisted by the likes of you!

    There is already a QML project example with saved dates marked using SQLite, yet I chose firebase for the cloud hosted backend, noSQL and no additional setup there for me! When you have said change the database type do you mean to stop using firebase and move to SQL? or is there a way I can translate my firebase callbacks into and SQL event model?

    Thanks a million again!!!

  • Lifetime Qt Champion

    Do you already have a way to connect to cloud firebase that works with Qt ?

  • @mrjj
    Yes i have already setup my database for user auth and can currently write the selected date to firebase and read back into the log. Its now using that read to also add the marker which is where i am stuck!!!

  • Lifetime Qt Champion

    Ok super.
    Next step would be to alter
    QList<QObject*> SqlEventModel::eventsForDate(const QDate &date)
    to use your table names / col names to get any events that need to be drawn.

    I assume you can use QSqlQuery with firebase or is that the actual issue ?
    its non sql and u use completely another method of getting data ?
    IF yes, i think we need to use other model then.

  • @mrjj

    firebase is noSQL with data stored as JSON so i have no tables to work with;
    a simple read value for me would be;


    I can query firebase also with filter by key/value/child options.

    Would you suggest working with Sql then?


  • @mrjj
    I have moved forward from calling my saved dates to receive the following:

    Read Value: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object] for key: dates

    (one for each date saved)
    when adding

    if(success) {

    I can also read the saved dates in the format of:


    now how would I determine these dates are saved in my calendar to add the marker?

    I have tried adding a property bool to the marker so the read value equals isMarked = true yet this either marks every date on the calendar or none at all depending on how I am working this?!?

    How would I convert the JSON string to individual date reads?