Page 1 of 2 12 LastLast
Results 1 to 20 of 26

Thread: display images in qt from text file

  1. #1
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default display images in qt from text file

    i have a text fileit contains set of jpeg images sorted in linux.this images should display in qtwidget in one after another for every 10 seconds based on timer concept ,can any one help me to do this.
    my text file below
    /home/ishwarya/displayimages/local/temp.txt
    total 284
    -rw-rw-r-- 1 ishwarya ishwarya 0 Dec 4 18:44 temp.txt
    -rw-rw-r-- 1 ishwarya ishwarya 6483 Dec 3 15:27 10.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 10069 Dec 3 15:25 27.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 8096 Dec 3 15:24 26.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 17116 Dec 3 15:24 25.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 10017 Dec 3 15:24 24.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 4912 Dec 3 15:24 23.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 4932 Dec 3 15:24 22.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 9031 Dec 3 15:24 21.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 5078 Dec 3 15:23 20.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 5741 Dec 3 15:23 19.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 9132 Dec 3 15:23 18.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 11094 Dec 3 15:23 17.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 4882 Dec 3 15:22 16.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 6402 Dec 3 15:22 15.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 3103 Dec 3 15:22 14.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 8484 Dec 3 15:22 13.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 6296 Dec 3 15:22 12.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 8051 Dec 3 15:21 11.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 8526 Dec 3 15:20 9.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 10177 Dec 3 15:20 8.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 12701 Dec 3 15:20 7.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 7803 Dec 3 15:20 6.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 7412 Nov 28 11:41 5.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 10559 Nov 28 11:38 4.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 7294 Nov 28 11:34 3.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 12722 Nov 28 11:29 2.jpeg
    -rw-rw-r-- 1 ishwarya ishwarya 6736 Nov 28 11:29 1.jpeg

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: display images in qt from text file

    What have you tried so far?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2013
    Location
    Bangalore, India
    Posts
    36
    Thanks
    9
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: display images in qt from text file

    Are those images stored inside some folder? or do you have only text file that contains the set of images? if you have images stored inside some folder, you can read all the ".jpeg" files inside that specific folder one by one for every 10 seconds and display it in QLabel.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: display images in qt from text file

    Quote Originally Posted by jakr13 View Post
    Are those images stored inside some folder? or do you have only text file that contains the set of images?
    The "text file" is a directory listing.

    This looks like the typical forum spammer, who opens several threads for exaclty the same topic, with no or slight modificatons to the content in order to bind as much volunteer effort as possible.

    Since I got spammed via PM as well, I am considering this a fact.

    Cheers,
    _

  5. #5
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: display images in qt from text file

    thank you friends..nw i sorted by jpeg images..and dispalying only very first images..bt i could not knw how to display every images one after another for evry 10 seconds.local folder contains images ,config file folder contains temp.txt file Guide me plsss
    my text file nd coding
    text file: /home/ishwarya/displayimages/configfile/temp.txt
    10.jpeg
    27.jpeg
    26.jpeg
    25.jpeg
    24.jpeg
    23.jpeg
    22.jpeg
    21.jpeg
    20.jpeg
    19.jpeg
    18.jpeg
    17.jpeg
    16.jpeg
    15.jpeg
    14.jpeg
    13.jpeg
    12.jpeg
    11.jpeg
    9.jpeg
    8.jpeg
    7.jpeg
    6.jpeg
    5.jpeg
    4.jpeg
    3.jpeg
    2.jpeg
    1.jpeg
    my coding
    Qt Code:
    1. #include "widget.h"
    2. #include "ui_widget.h"
    3. #include <QtGui>
    4. Widget::Widget(QWidget *parent) :
    5. QWidget(parent),
    6. ui(new Ui::Widget)
    7. {
    8.  
    9.  
    10. QString filePath1("/home/ishwarya/displayimages/configfile");// path for temp.txt file
    11. QString filePath2("/home/ishwarya/displayimages/local");// path for images
    12. QString sortedimagesfilenameslist="temp.txt";// it contains list of sorted images
    13. QDir dir;
    14. dir.cd(filePath1);
    15. QFile file;
    16. file.setFileName(dir.absoluteFilePath(sortedimagesfilenameslist));
    17.  
    18. file.open(QIODevice::ReadOnly);
    19.  
    20. QTextStream stream( &file );
    21. QString imagefilename;
    22.  
    23.  
    24. imagefilename= stream.readLine();
    25. qDebug()<<imagefilename;
    26. dir.cd(filePath2);
    27. qDebug()<<dir;
    28. QFile file1;
    29. file1.setFileName(dir.absoluteFilePath(imagefilename));
    30. qDebug()<<file1.exists();
    31.  
    32. QImage *img = new QImage(dir.absoluteFilePath(imagefilename));
    33. imageLabel=new QLabel(this);
    34. QPixmap map = QPixmap::fromImage(img->scaled(900,900,Qt::KeepAspectRatio,Qt::FastTransformation));
    35. imageLabel->setPixmap(map);
    36. imageLabel->showFullScreen();
    37. imageLabel->show();
    38. ui->setupUi(this);
    39. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 11th December 2014 at 08:53. Reason: missing [code] tags

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: display images in qt from text file

    Is this some kind of school project?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2013
    Location
    Bangalore, India
    Posts
    36
    Thanks
    9
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: display images in qt from text file

    You can check the program attached, which I did few years back and I think you will get some ideas from it. I used C++ style to read the directory and I have a pushbutton in GUI to start displaying images in label. You can have QTimer in constructor instead of pushbutton.

    Note: dirent.h will works on linux but i doubt on windows.

    cheers!!!
    Attached Files Attached Files
    Last edited by jakr13; 8th December 2014 at 09:47.

  8. #8
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: display images in qt from text file

    thank you so much sir
    Quote Originally Posted by jakr13 View Post
    You can check the program attached, which I did few years back and I think you will get some ideas from it. I used C++ style to read the directory and I have a pushbutton in GUI to start displaying images in label. You can have QTimer in constructor instead of pushbutton.

    Note: dirent.h will works on linux but i doubt on windows.

    cheers!!!

    Added after 20 minutes:


    hello Mr. wysota.
    Am a fresher sir jus nw i joined Embedded with Qt .nw training was going on..sir
    Last edited by iswaryasenthilkumar; 8th December 2014 at 11:21.

  9. #9
    Join Date
    Jan 2013
    Location
    Bangalore, India
    Posts
    36
    Thanks
    9
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: display images in qt from text file

    Hi iswarya,

    check the updated piece of code attached to help you how the QTimer can be used in a constructor!!!

    jakr13
    Attached Files Attached Files

  10. #10
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: display images in qt from text file

    thank you sir
    bt in my concept i have two file one file was jpeg images another file was sorted images with name sir i have to combine this both
    Quote Originally Posted by jakr13 View Post
    Hi iswarya,

    check the updated piece of code attached to help you how the QTimer can be used in a constructor!!!

    jakr13

    Added after 4 minutes:


    my task concept was:
    i have a folder it contains lot of jpeg images..i have to sort this images and putd in textfile by linux.i have one more file it contains timer
    it says local image=10 seconds,by reading this timer file i have to display the images for evry 10 seconds.so my codinf should link sorted text file ,timer text file,images file(jpeg).

    i want to show slideshow.. (every 10 seconds images should automaticaly change)
    this was my concept sir
    sir pls kindly help me in my coding itself sir
    using for loop i can able to display every images after 10 seconds,,i dnt knw how to put
    so pls help me sir
    my coding
    Qt Code:
    1. #include "widget.h"
    2. #include "ui_widget.h"
    3. #include <QtGui>
    4. Widget::Widget(QWidget *parent) :
    5. QWidget(parent),
    6. ui(new Ui::Widget)
    7. {
    8. QString filePath1("/home/ishwarya/displayimages/configfile");// path for temp.txt file
    9. QString filePath2("/home/ishwarya/displayimages/local");// path for images
    10. QString sortedimagesfilenameslist="temp.txt";// it contains list of sorted images
    11. QDir dir;
    12. dir.cd(filePath1);
    13. QFile file;
    14. file.setFileName(dir.absoluteFilePath(sortedimages filenameslist));
    15. file.open(QIODevice::ReadOnly);
    16. QTextStream stream( &file );
    17. QString imagefilename;
    18. imagefilename= stream.readLine();
    19. qDebug()<<imagefilename;
    20. dir.cd(filePath2);
    21. qDebug()<<dir;
    22. QFile file1;
    23. file1.setFileName(dir.absoluteFilePath(imagefilena me));
    24. qDebug()<<file1.exists();
    25. QImage *img = new QImage(dir.absoluteFilePath(imagefilename));
    26. imageLabel=new QLabel(this);
    27. QPixmap map = QPixmap::fromImage(img->scaled(900,900,Qt::KeepAspectRatio,Qt::FastTransf ormation));
    28. imageLabel->setPixmap(map);
    29. imageLabel->showFullScreen();
    30. imageLabel->show();
    31. ui->setupUi(this);
    32. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 11th December 2014 at 08:53. Reason: missing [code] tags

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: display images in qt from text file

    Again, is this a school project of some sort?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: display images in qt from text file

    i dnt knw abt its either school project or training project...bt this was my task sir..
    Quote Originally Posted by wysota View Post
    Again, is this a school project of some sort?

  13. #13
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: display images in qt from text file

    hello Mr jakr13
    your code was so usefull to me.. thank you so much friend

  14. #14
    Join Date
    Jan 2013
    Location
    Bangalore, India
    Posts
    36
    Thanks
    9
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: display images in qt from text file

    got it working?

    One more suggestion. You said you have three tasks. Its better that you make separate functions for every task and make function call.
    Last edited by jakr13; 9th December 2014 at 09:05.

  15. #15
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: display images in qt from text file

    k friend..bt i have one doubt..i completed local folder images for evry 10 seconds.i have one more folder [remote folder] it should display evry 5th minutes..my TL told read current time,, in that take seconds and make divide by 5 if its true display first images of remote folder for 10 seconds and go to remaing local folder images to display..
    did yu knw how to calculate seconds from current time..plss help me frnd

  16. #16
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: display images in qt from text file

    Quote Originally Posted by iswaryasenthilkumar View Post
    did yu knw how to calculate seconds from current time..plss help me frnd
    Why don't you use a QTimer with an interval of 300 seconds (5*60) and connect the timer to the timeout signal to a slot in your app?

    If you must calculate the seconds yourself for some reason, either QDateTime or QTime can be used to get the number of miliseconds and divide by 1,000 to get the number of seconds.

  17. #17
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: display images in qt from text file

    i calculated sir bt its not properly working for evry 5th minute..
    my coding
    Qt Code:
    1. QTime time = QTime::currentTime();
    2. if((time.second() %5 ) == 0)
    3. {
    4. ReadImagesfromRemoteFolder();
    5. }
    To copy to clipboard, switch view to plain text mode 
    plss help me ...
    Last edited by wysota; 11th December 2014 at 08:54. Reason: missing [code] tags

  18. #18
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: display images in qt from text file

    You do understand that seconds and minutes are two different units of time, right?

    Cheers,
    _

  19. #19
    Join Date
    Nov 2014
    Location
    Chennai
    Posts
    160
    Thanks
    65
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: display images in qt from text file

    thanks its working bt again one problem for evry 5th minute remote folder should display on image for 10 seconds next remaining local folder images should display..bt for me evry 5th minutes remote folder image dispalying next local images start from begining.. can any one help me plss.
    Quote Originally Posted by anda_skoa View Post
    You do understand that seconds and minutes are two different units of time, right?

    Cheers,
    _
    Last edited by iswaryasenthilkumar; 10th December 2014 at 10:54.

  20. #20
    Join Date
    Jan 2013
    Location
    Bangalore, India
    Posts
    36
    Thanks
    9
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: display images in qt from text file

    Quote Originally Posted by iswaryasenthilkumar View Post
    thanks its working bt again one problem for evry 5th minute remote folder should display on image for 10 seconds next remaining local folder images should display..bt for me evry 5th minutes remote folder image dispalying next local images start from begining.. can any one help me plss.
    If I am not wrong, you should display image from remote folder for every 5th minute for 10 seconds and after that local images must be displayed. Am I right?

    do you need the local images to be displayed every 10 seconds after that 5th minute 10 seconds?

    if this is the case,you know now how to display images after 5th minute. After that, you can call the delay loop in my program which uses QTime::currenttime.addsecs(10) after calling the function "ReadFromRemoteFolder". It displays for 10 seconds after the 5th minute. Then read the images from the local folder for every 10sec.

    jakr13
    Last edited by jakr13; 10th December 2014 at 15:20.

Similar Threads

  1. Replies: 1
    Last Post: 31st October 2014, 07:32
  2. Replies: 2
    Last Post: 22nd September 2012, 01:18
  3. How to display text from a file to a text browser
    By ironmantis7x in forum Newbie
    Replies: 11
    Last Post: 14th June 2012, 15:23
  4. Saving Text and Images as a file
    By rleojoseph in forum Qt Programming
    Replies: 2
    Last Post: 15th February 2011, 09:15
  5. Widget to display images and text ?
    By probine in forum Qt Tools
    Replies: 4
    Last Post: 9th October 2006, 20:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.