Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Displaying set of images based on time

Displaying set of images based on time

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 198 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • QjayQ Offline
    QjayQ Offline
    Qjay
    wrote on last edited by
    #1

    Hello , i have a set of images that are locally stored in system and have a database which looks something like this

    0_1538476666857_db.png

    When the user opens the app , it should read the system time and get the image based on which is closest to current time .

    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

    QString return_diff(QHash<QString, QString> mantra)
    {
        QTime sys_time;
        QHash<QString, QTime>result;
            sys_time =  QTime::currentTime();
        QHashIterator<QString, QString> 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 >= sys_time)
            {
                result.insert(server_timeID,notify_time);
            }
    
        }
        QString image;
        QHashIterator<QString, QTime> j(result);
        QTime min(0,0,0,0);
        while(j.hasNext())
        {
            if(j.value() < min)
            {
                image = j.key();
            }
        }
    
    
        return image;
    
    
    }
    
    QString dbmanager::getImage_url()
    {
        QString db_path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
        QString email = "";
    
        qDebug() << 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() <<"error in opening DB";
           }
           else
           {
               qDebug() <<"connected to DB" ;
    
           }
           QSqlQuery query;
           QString image;
    
           query.prepare("SELECT email from User where ID = 1");
    
    
           if(query.exec() && (query.size() > 0 || query.size() != -1))
           {
              qDebug() << "done";
              email = query.value(0).toString();
              QHash<QString, QString> 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;
    
    }
    
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved