Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Solved]Save image with dynamic name
Forum Updated to NodeBB v4.3 + New Features

[Solved]Save image with dynamic name

Scheduled Pinned Locked Moved Mobile and Embedded
7 Posts 3 Posters 3.6k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    daljit97
    wrote on last edited by
    #1

    I'm a beginning "developer" and i'm newbie to qt and c++.
    So, my problem: I've a custom c++ class that save an image to a file(in symbian device), it works perfectly. Now i want to set a dynamic filename for it,with current date and time. I've tried different solutions but i failed. Here's code. Can any one help me to get an easy solution?

    @SaveImage::SaveImage(QObject*parent):
    QObject(parent)
    {
    }
    void SaveImage::save(QDeclarativeItem *item)
    {
    QDateTime dateTime = QDateTime::currentDateTime();
    QString dateTimeString = dateTime.toString();
    QPixmap pix(item->width(), item->height());
    QPainter painter(&pix);
    QStyleOptionGraphicsItem option;
    item->paint(&painter, &option, NULL);
    //i've tried this but doesn't work: pix.save("E:/Images/"image"+dateTimeString+".jpg");
    }@

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      I'm not familiar with symbian. Does it HAVE the concept of named drives ("E:" in your code)?

      What I suggest, is: verify that the chosen path exists. Then, make sure you have write permission in that folder.

      (Z(:^

      1 Reply Last reply
      0
      • D Offline
        D Offline
        daljit97
        wrote on last edited by
        #3

        Oh the class works prefectly using this code: pix.save("E:/Images/"image/image.jpg");
        but my problem is that i want to subsitute the name of the file with current date and time.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          QDateTime documentation says that default output of ::toString() is "Wed May 20 03:40:13 1998". Does symbian support spaces and colons in folder names? I would specify my own date format, if I were you (see QDateTime docs). Also, verify the path at runtime with qDebug() or by debugging.

          (Z(:^

          1 Reply Last reply
          0
          • D Offline
            D Offline
            daljit97
            wrote on last edited by
            #5

            Thanks, you were right symbian doesn't support colons in file names. So here the working code.
            @SaveImage::SaveImage(QObject*parent):
            QObject(parent)
            {
            }
            void SaveImage::save(QDeclarativeItem *item)
            {
            QDateTime dateTime = QDateTime::currentDateTime();
            QString dateTimeString = dateTime.toString("hh_mm_ss yyyy_MMM_dd");
            QPixmap pix(item->width(), item->height());
            QPainter painter(&pix);
            QStyleOptionGraphicsItem option;
            item->paint(&painter, &option, NULL);
            pix.save("E:/Images/"+dateTimeString+".jpg");
            qDebug() << "Captured on Symbian,here: E:/Images/";
            }@

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              Great!

              Please add "[Solved]" at the beginning of the subject of this thread to make it easier for other people with similar problem in the future.

              (Z(:^

              1 Reply Last reply
              0
              • C Offline
                C Offline
                CreMindES
                wrote on last edited by
                #7

                Oh, and thanks for posting the working code, it's always a big help to see a code snippet for a problem and then the solution as well :)

                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