<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Displaying set of images based on time]]></title><description><![CDATA[<p dir="auto">Hello , i have a set of images  that are locally stored in system and have a database which looks something like this</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/b7e19ebc-e954-4137-9403-1dfe1e4a7030.png" alt="0_1538476666857_db.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">When the user opens the app , it should read the system time and get the image based on which is closest to current time .</p>
<p dir="auto">currently i am doing  something like this , don't know if it's right way but if you guys have better more optimized way please suggest. Below is the code</p>
<pre><code>QString return_diff(QHash&lt;QString, QString&gt; mantra)
{
    QTime sys_time;
    QHash&lt;QString, QTime&gt;result;
        sys_time =  QTime::currentTime();
    QHashIterator&lt;QString, QString&gt; i(mantra);
    while(i.hasNext())
    {
        QString server_timeID = i.key();
        QString server_time = i.value();
        QStringList splitted_time = server_time.split(":");

        QString hrs = splitted_time.at(0);
        QString min = splitted_time.at(1);
        int int_hrs =hrs.toInt();
        int int_min = min.toInt();
        QTime notify_time(int_hrs,int_min,0,0);
        if(notify_time &gt;= sys_time)
        {
            result.insert(server_timeID,notify_time);
        }

    }
    QString image;
    QHashIterator&lt;QString, QTime&gt; j(result);
    QTime min(0,0,0,0);
    while(j.hasNext())
    {
        if(j.value() &lt; min)
        {
            image = j.key();
        }
    }


    return image;


}

QString dbmanager::getImage_url()
{
    QString db_path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
    QString email = "";

    qDebug() &lt;&lt; db_path;
    QDir dir(db_path);
    dir.cd("MANTRA_appdata");

    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");//not dbConnection
       db.setDatabaseName(dir.absoluteFilePath("MANTRA.db"));
       if(!db.open())
       {
           qDebug() &lt;&lt;"error in opening DB";
       }
       else
       {
           qDebug() &lt;&lt;"connected to DB" ;

       }
       QSqlQuery query;
       QString image;

       query.prepare("SELECT email from User where ID = 1");


       if(query.exec() &amp;&amp; (query.size() &gt; 0 || query.size() != -1))
       {
          qDebug() &lt;&lt; "done";
          email = query.value(0).toString();
          QHash&lt;QString, QString&gt; mantra;
          query.prepare("SELECT mantra_type time FROM Mantra WHERE enabled = true AND email = '" + email + "'");
          while(query.next())
          {
              mantra.insert(query.value(0).toString(),query.value(0).toString());
          }

          image = return_diff(mantra);

       }
       else
       {
           image = "Mantra1.png";
       }
       image = dir.absolutePath() + "/" + image;


       return image;

}

</code></pre>
]]></description><link>https://forum.qt.io/topic/95192/displaying-set-of-images-based-on-time</link><generator>RSS for Node</generator><lastBuildDate>Wed, 11 Nov 2026 00:41:50 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/95192.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 02 Oct 2018 10:41:00 GMT</pubDate><ttl>60</ttl></channel></rss>