PDA

View Full Version : display images in qt from text file



iswaryasenthilkumar
5th December 2014, 08:57
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.:confused::(
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

wysota
5th December 2014, 09:31
What have you tried so far?

jakr13
5th December 2014, 11:02
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.

anda_skoa
5th December 2014, 15:09
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,
_

iswaryasenthilkumar
8th December 2014, 05:00
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

#include "widget.h"
#include "ui_widget.h"
#include <QtGui>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{


QString filePath1("/home/ishwarya/displayimages/configfile");// path for temp.txt file
QString filePath2("/home/ishwarya/displayimages/local");// path for images
QString sortedimagesfilenameslist="temp.txt";// it contains list of sorted images
QDir dir;
dir.cd(filePath1);
QFile file;
file.setFileName(dir.absoluteFilePath(sortedimages filenameslist));

file.open(QIODevice::ReadOnly);

QTextStream stream( &file );
QString imagefilename;


imagefilename= stream.readLine();
qDebug()<<imagefilename;
dir.cd(filePath2);
qDebug()<<dir;
QFile file1;
file1.setFileName(dir.absoluteFilePath(imagefilena me));
qDebug()<<file1.exists();

QImage *img = new QImage(dir.absoluteFilePath(imagefilename));
imageLabel=new QLabel(this);
QPixmap map = QPixmap::fromImage(img->scaled(900,900,Qt::KeepAspectRatio,Qt::FastTransfo rmation));
imageLabel->setPixmap(map);
imageLabel->showFullScreen();
imageLabel->show();
ui->setupUi(this);
}

wysota
8th December 2014, 08:50
Is this some kind of school project?

jakr13
8th December 2014, 09:22
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!!!

iswaryasenthilkumar
8th December 2014, 11:21
thank you so much sir

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

jakr13
8th December 2014, 11:22
Hi iswarya,

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

jakr13

iswaryasenthilkumar
8th December 2014, 11:32
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
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

#include "widget.h"
#include "ui_widget.h"
#include <QtGui>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
QString filePath1("/home/ishwarya/displayimages/configfile");// path for temp.txt file
QString filePath2("/home/ishwarya/displayimages/local");// path for images
QString sortedimagesfilenameslist="temp.txt";// it contains list of sorted images
QDir dir;
dir.cd(filePath1);
QFile file;
file.setFileName(dir.absoluteFilePath(sortedimages filenameslist));
file.open(QIODevice::ReadOnly);
QTextStream stream( &file );
QString imagefilename;
imagefilename= stream.readLine();
qDebug()<<imagefilename;
dir.cd(filePath2);
qDebug()<<dir;
QFile file1;
file1.setFileName(dir.absoluteFilePath(imagefilena me));
qDebug()<<file1.exists();
QImage *img = new QImage(dir.absoluteFilePath(imagefilename));
imageLabel=new QLabel(this);
QPixmap map = QPixmap::fromImage(img->scaled(900,900,Qt::KeepAspectRatio,Qt::FastTransf ormation));
imageLabel->setPixmap(map);
imageLabel->showFullScreen();
imageLabel->show();
ui->setupUi(this);
}

wysota
8th December 2014, 12:20
Again, is this a school project of some sort?

iswaryasenthilkumar
8th December 2014, 12:57
i dnt knw abt its either school project or training project...bt this was my task sir..

Again, is this a school project of some sort?

iswaryasenthilkumar
9th December 2014, 05:43
hello Mr jakr13
your code was so usefull to me.. thank you so much friend

jakr13
9th December 2014, 08:58
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.

iswaryasenthilkumar
10th December 2014, 04:46
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:(

jefftee
10th December 2014, 06:28
did yu knw how to calculate seconds from current time..plss help me frnd:(
Why don't you use a QTimer (http://qt-project.org/doc/qt-5/qtimer.html) with an interval of 300 seconds (5*60) and connect the timer to the timeout (http://qt-project.org/doc/qt-5/qtimer.html#timeout) signal to a slot in your app?

If you must calculate the seconds yourself for some reason, either QDateTime (http://qt-project.org/doc/qt-5/qdatetime.html) or QTime (http://qt-project.org/doc/qt-5/qtime.html) can be used to get the number of miliseconds and divide by 1,000 to get the number of seconds.

iswaryasenthilkumar
10th December 2014, 09:28
i calculated sir bt its not properly working for evry 5th minute..
my coding

QTime time = QTime::currentTime();
if((time.second() %5 ) == 0)
{
ReadImagesfromRemoteFolder();
}
plss help me ...

anda_skoa
10th December 2014, 09:56
You do understand that seconds and minutes are two different units of time, right?

Cheers,
_

iswaryasenthilkumar
10th December 2014, 10:24
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.

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

Cheers,
_

jakr13
10th December 2014, 15:09
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

jefftee
10th December 2014, 23:46
i calculated sir bt its not properly working for evry 5th minute..

There are 300 seconds in a 5 minute period, so not sure why you're modding the seconds by 5 and expecting that to equate to 5 minutes. Also, I don't know how your section of code is executed, but even if you change to:



if ((time.second() % 300) == 0)

Your code would have to execute exactly on every 5th minute or else you'd miss the window until the next 5 minute (300 seconds) interval. You really should use a QTimer here IMHO.

iswaryasenthilkumar
11th December 2014, 04:56
help me sir...

Added after 6 minutes:

ya this only i putd sir bt my problem is remote folder displaying only two images of evry 5 th minute,its not dispalying remaining images in remote folder.. can you pls check my code and rectify my problem plsss.
my coding

void Widget::ReadImagesfromlocalFolder()
{

QString filePath1("/home/ishwarya/displayimages/configfile");
QString filePath2("/home/ishwarya/displayimages/local");
QString sortedimagesfilenameslist="temp.txt";
dir.cd(filePath1);
QFile file;
file.setFileName(dir.absoluteFilePath(sortedimages filenameslist));
file.open(QIODevice::ReadOnly);
QTextStream stream( &file );
QString imagefilename[100];
for(int i=0;i<31;i++)
{
showFullScreen();
activateWindow();
imagefilename[i]= stream.readLine();
qDebug()<<"local:"<<imagefilename[i];
dir.cd(filePath2);
QFile file1;
file1.setFileName(dir.absoluteFilePath(imagefilena me[i]));
QImage ImageToLoad;
ImageToLoad.load(dir.absoluteFilePath(imagefilenam e[i]));
QLabel *label = new QLabel(this);
label->setPixmap(QPixmap::fromImage(ImageToLoad.scaled(90 0,900,Qt::KeepAspectRatio,Qt::FastTransformation)) );
label->showFullScreen();
delay();

}

}
void Widget::ReadImagesfromRemoteFolder()
{
int j=0;
QString filePath1("/home/ishwarya/displayimages/configfile");
QString filePath2("/home/ishwarya/displayimages/remote");
QString sortedimagesfilenameslist="tempp.txt";
dir.cd(filePath1);
QFile file;
file.setFileName(dir.absoluteFilePath(sortedimages filenameslist));
file.open(QIODevice::ReadOnly);
QTextStream stream( &file );
QString imagefilename[24];
for(j=0;j<24;j++)
{
showFullScreen();
activateWindow();
imagefilename[j]= stream.readLine();
qDebug()<<"remote:"<<imagefilename[j];
dir.cd(filePath2);
QFile file1;
file1.setFileName(dir.absoluteFilePath(imagefilena me[j]));
QImage ImageToLoad;
ImageToLoad.load(dir.absoluteFilePath(imagefilenam e[j]));
QLabel *label = new QLabel(this);
label->setPixmap(QPixmap::fromImage(ImageToLoad.scaled(90 0,900,Qt::KeepAspectRatio,Qt::FastTransformation)) );
label->showFullScreen();
delay();
ReadImagesfromlocalFolder();
}
}

void Widget::delay()
{
QTime time = QTime::currentTime();

if((time.second() % 300 ) == 0)
{

ReadImagesfromRemoteFolder();

}


if(checklocalseconds=="local=10seconds")
{
sleepTime = QTime::currentTime().addSecs(10);
while(QTime::currentTime() < sleepTime);
qDebug()<<"check";
QApplication::processEvents(QEventLoop::AllEvents, 1000);
}

}

There are 300 seconds in a minute, so not sure why you're modding the seconds by 5 and expecting that to equate to 5 minutes. Also, I don't know how your section of code is executed, but even if you change to:



if ((time.seconds() % 300) == 0)

Your code would have to execute exactly on every 5th minute or else you'd miss the window until the next 5 minute (300 seconds) interval. You really should use a QTimer here IMHO.

jefftee
11th December 2014, 05:44
help me sir...
I have attempted to help you, however, you have ignored everything I have said. Ultimately, you are trying to brute force a solution when Qt provides a much more flexible and easy to implement event driven mechanism using QTimer and signals and slots.

You really need to spend some time understanding Qt and reading the documentation... For example, I just read the documentation for QTime::second() and it returns the seconds portion of the QTime, which is a value between 0-59, so you won't succeed with that approach.

If I understand what you are trying to accomplish, and it's very hard to figure it out IMHO, you want to display a local image every 10 seconds, except for every 5th minute (300 seconds), you want to display a remote image. If that is close to what you are trying to achieve, then you should:



Use QTime and QTime::start() during your program's initialization.
Use a QTimer with a 10 second interval and connect the QTimer timeout() signal to a slot in your program.
In the slot above you can use QTime::elapsed() on the QTime variable you started in step 1.
Divide the elapsed milliseconds by 1,000 to get the number of seconds.
If seconds >= 300, display your remote image and use QTime::restart() to restart the QTime again.
If seconds < 300, display a local image.


Your slot will then be invoked again after 10 seconds until you stop the QTimer during your program's termination. If this doesn't help you, I'm afraid I can't help you... :)

iswaryasenthilkumar
11th December 2014, 07:56
nt like that sir..am a fresher sir,, i dnt knw hw to do... am nw only learning QT..

wysota
11th December 2014, 08:36
nt like that sir..am a fresher sir,, i dnt knw hw to do... am nw only learning QT..

So learn instead of taking on tasks you have not a slightest idea how to solve. Qt is not your problem, your problem is inability to come up with an algorithm which will solve the task at hand. Jthomps had a lot of patience for you but you clearly indicate no interest in investing your time to learn anything so I am not surprised he got fed up with your slideshow. If you want to learn then start with something simple and when you gain experience you can work on more complex code. If you are expecting to get a ready working solution, then people here are smart enough not to give it to you. And please finally stop this trash-talking, if you are unable to formulate a proper sentence in English then it means you pay no respect to people trying to help you.

iswaryasenthilkumar
11th December 2014, 09:22
K sir..I will try to improve my knowledge in Algorithm