PDA

View Full Version : Create images slideshow in c++



Rd1912
8th September 2019, 11:57
I want to Devlope slideshow of images available in qrc file when I click on left key and right key it will show next image . Can anyone give some idea for that or any reference file to me that help me to create this?

d_stranz
8th September 2019, 20:45
The usual way to load and display images is using a QLabel to display the image and QPixmap or QImage to load the image from the resource file using the "qrc:///path-to-resource/image-file.png" or ":/path-to-resource/image-file.png" resource file name conventions.

To change the pictures, you will need to implement an event handler for QWidget::keyPressEvent() or QWidget::keyReleaseEvent(), looking for QKeyEvent::key() values equal to Qt::Key_Left or Qt::Key_Right.

The easiest way is to derive a new class from QLabel and override the keyPressEvent() or keyReleaseEvent(). In your event handler, you load the next image from the qrc file and display it using QLabel::setPixmap().

I am not going to give you source code. This sounds a lot like a homework project, and the goal of homework is to force you to learn how to solve your own programming problems.

Rd1912
17th September 2019, 18:21
When I use key press(QKeyEvent *event) and then inside I use if else to check key using event->key() value equal to Qt:Key_Left or Right and i increase value of I and then I use stringlist to store more image paths and show in label using this statement


Ui->label->setPixmap(image paths[ยก]) but when I run and press key my application forcefully close

d_stranz
17th September 2019, 19:34
but when I run and press key my application forcefully close

The you need to make a Debug version of your program, run it in the debugger, and find out what is causing the crash. In the one line of code you posted, I see at least four things that could cause a crash:

1 - Does "Ui" contain a valid pointer?
2 - Does "label" contain valid pointer, and does it point to a QLabel instance?
3 - Does "i" have a valid value?
4 - Does "image paths[i]" contain a valid path name?
5 - Did the call to setPixmap() succeed?

Your code doesn't check for any errors, and it assumes everything will work perfectly.

Rd1912
18th September 2019, 18:03
What is means sigabrt signal that cause my application crash?

Ginsengelf
19th September 2019, 13:05
Hi, sigabrt is for example used by the C library to notify your program of critical error, e.g. problems with the heap.

Ginsengelf

Rd1912
20th September 2019, 07:12
Can anyone tell how to access stringlist where I save all path of my images.


QPixmap slide = QPixmap(d->imagePaths[d->currentSlide]);
}
In this code this line will create problem and give sigabrt signal. Can you please tell how to access element in list?

d_stranz
20th September 2019, 16:12
If you want help, you are going to have to show more than one line of code. Show the code that gives the definitions (data types) for "d", "imagePaths", and "currentSlide" and show how you are loading these variables with values. In other words, copy enough of your actual code that we could study it and try to find your error.

Rd1912
3rd October 2019, 14:14
i able to detect error that lead crash.it is because i (for list) not getting valid value. now it works fine.