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. Create slideshow in qt creator
Forum Updated to NodeBB v4.3 + New Features

Create slideshow in qt creator

Scheduled Pinned Locked Moved Solved Mobile and Embedded
qtcreator 5.11qlist
20 Posts 4 Posters 4.2k Views 3 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 27 Sept 2019, 18:20 last edited by
    #8

    If it crashed then there's likely an error in your code. Did you try to debug it ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    R 1 Reply Last reply 28 Sept 2019, 08:04
    1
    • S SGaist
      27 Sept 2019, 18:20

      If it crashed then there's likely an error in your code. Did you try to debug it ?

      R Offline
      R Offline
      RAJ Dalsaniya
      wrote on 28 Sept 2019, 08:04 last edited by
      #9

      @SGaist Yes ...I think way I am access my list of link...it creates trouble..

      M 1 Reply Last reply 28 Sept 2019, 13:10
      0
      • R RAJ Dalsaniya
        28 Sept 2019, 08:04

        @SGaist Yes ...I think way I am access my list of link...it creates trouble..

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 28 Sept 2019, 13:10 last edited by
        #10

        @RAJ-Dalsaniya
        Hi
        please show the c++ code then. :)

        1 Reply Last reply
        1
        • R Offline
          R Offline
          RAJ Dalsaniya
          wrote on 2 Oct 2019, 04:33 last edited by
          #11

          f1_image.cpp

          #include "f1_image.h"
          #include "ui_f1_image.h"
          
          #include<QGraphicsView>
          #include<QStringList>
          #include<QList>
          #include<QDir>
          #include<iostream>
          #include<QWidget>
          #include <QKeyEvent>
          #include <QStringList>
          
          
          class f1_image_private
          {
          public:
              f1_image_private();
          
              int CurrentSlide;
          
          };
          
          F1_Image::F1_Image(QDialog *parent) :
              QDialog(parent),
              ui(new Ui::F1_Image)
          {
              ui->setupUi(this);
              filenames.append(":/f1/F1_IMG/city.jpg");
              filenames.append(":/f1/F1_IMG/cycle.jpg");
              filenames.append(":/f1/F1_IMG/design.jpg");
              filenames.append(":/f1/F1_IMG/nature.jpg");
              filenames.append(":/f1/F1_IMG/tree.jpg");
          
          }
          
          F1_Image::~F1_Image()
          {
              delete ui;
          }
          
          void F1_Image::paintEvent(QPaintEvent *event)
          {
              QPainter painter(this);
              painter.setRenderHint(QPainter::Antialiasing, false);
              if (filenames.size() > 0)
              {
                  ui->image->setPixmap(filenames.at(i));
              }
          }
          
          void F1_Image::keyPressEvent(QKeyEvent* event)
          {
              if(event->key()==Qt::Key_Left)
              {
                  i++ ;
              }
              else if(event->key()==Qt::Key_Right)
              {
                  i--;
              }
          
          }
          

          f1_image.h

          #ifndef F1_IMAGE_H
          #define F1_IMAGE_H
          
          #include <QDialog>
          #include <QStringList>
          #include <QGraphicsScene>
          
          namespace Ui {
          class F1_Image;
          }
          
          class F1_image_private;
          
          class F1_Image : public QDialog
          {
              Q_OBJECT
          
          public:
              explicit F1_Image(QDialog *parent = nullptr);
              ~F1_Image();
              void addImage(QStringList filenames);
          
              QStringList filenames;
              int i=0;
          
          private:
              Ui::F1_Image *ui;
              Ui::F1_Image *d;
              QPixmap image;
              QImage *imageObject;
              QGraphicsScene *scene;
          
          signals:
              void inputReceived();
          
          protected:
               void keyPressEvent(QKeyEvent *event);
               void paintEvent(QPaintEvent *event);
              // void showEvent(QShowEvent *event );
          };
          
          

          @SGaist @mrjj this is my code. i am not sure where excatly i am doing wrong. can you please help me??

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 2 Oct 2019, 07:50 last edited by mrjj 10 Feb 2019, 09:33
            #12

            Hi
            It does not look very wrong.
            At least not something app should crash from.
            (not unless you press right from start and i becomes -1)

            You don't need the
            void F1_Image::paintEvent(QPaintEvent *event)
            as the QLabel can paint itself and since you are
            not painting anything else it seems wasted.
            However, in sample, i used to print i on same form.

            You can call setPixmap in keypressEvent

            void F1_Image::keyPressEvent(QKeyEvent* event)
            {
                if(event->key()==Qt::Key_Left)
                {
                    i++ ;
                }
                else if(event->key()==Qt::Key_Right)
                {
                    i--;
                }
            
             
                int maxSize = filenames.size() - 1;
                // checks to make it round trip / avoid crashing
                if (i > maxSize) { i = 0; }
                if (i < 0 ) { i = maxSize; }
            
                if (i <= maxSize && i >= 0) {
                    ui->label->setPixmap(filenames.at(i));
                }
            
            }
            

            also in .h
            Ui::F1_Image *d;
            That looks a little odd but just a pointer so should not do anything.

            Make sure that you check i against being negative also.
            If user press right as first key, the i will be -1 and also crash the list.

            here is a working sample based on your code.
            https://www.dropbox.com/s/ykfm3hqr1x3clby/slideshow_test.zip?dl=0

            R 1 Reply Last reply 2 Oct 2019, 10:51
            2
            • M mrjj
              2 Oct 2019, 07:50

              Hi
              It does not look very wrong.
              At least not something app should crash from.
              (not unless you press right from start and i becomes -1)

              You don't need the
              void F1_Image::paintEvent(QPaintEvent *event)
              as the QLabel can paint itself and since you are
              not painting anything else it seems wasted.
              However, in sample, i used to print i on same form.

              You can call setPixmap in keypressEvent

              void F1_Image::keyPressEvent(QKeyEvent* event)
              {
                  if(event->key()==Qt::Key_Left)
                  {
                      i++ ;
                  }
                  else if(event->key()==Qt::Key_Right)
                  {
                      i--;
                  }
              
               
                  int maxSize = filenames.size() - 1;
                  // checks to make it round trip / avoid crashing
                  if (i > maxSize) { i = 0; }
                  if (i < 0 ) { i = maxSize; }
              
                  if (i <= maxSize && i >= 0) {
                      ui->label->setPixmap(filenames.at(i));
                  }
              
              }
              

              also in .h
              Ui::F1_Image *d;
              That looks a little odd but just a pointer so should not do anything.

              Make sure that you check i against being negative also.
              If user press right as first key, the i will be -1 and also crash the list.

              here is a working sample based on your code.
              https://www.dropbox.com/s/ykfm3hqr1x3clby/slideshow_test.zip?dl=0

              R Offline
              R Offline
              RAJ Dalsaniya
              wrote on 2 Oct 2019, 10:51 last edited by
              #13

              @mrjj now my application don't crashing but it doesn't show images.

              M 1 Reply Last reply 2 Oct 2019, 11:02
              0
              • R RAJ Dalsaniya
                2 Oct 2019, 10:51

                @mrjj now my application don't crashing but it doesn't show images.

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 2 Oct 2019, 11:02 last edited by
                #14

                @RAJ-Dalsaniya

                Well your code works fine in the sample
                so i cannot guess why it does not for you.

                Use the debugger and check what happens when you press a key
                and check the the value of i.

                Also , set an image to the QLabel in CTOR so it has something to show from start.

                Make sure you check that i is valid.

                The sample does the above if you have doubts.

                R 1 Reply Last reply 2 Oct 2019, 11:27
                0
                • M mrjj
                  2 Oct 2019, 11:02

                  @RAJ-Dalsaniya

                  Well your code works fine in the sample
                  so i cannot guess why it does not for you.

                  Use the debugger and check what happens when you press a key
                  and check the the value of i.

                  Also , set an image to the QLabel in CTOR so it has something to show from start.

                  Make sure you check that i is valid.

                  The sample does the above if you have doubts.

                  R Offline
                  R Offline
                  RAJ Dalsaniya
                  wrote on 2 Oct 2019, 11:27 last edited by
                  #15

                  @mrjj I set one other label to check I value and it changed according to keypress but label where I show picture it has some issue..

                  M 1 Reply Last reply 2 Oct 2019, 11:33
                  0
                  • R RAJ Dalsaniya
                    2 Oct 2019, 11:27

                    @mrjj I set one other label to check I value and it changed according to keypress but label where I show picture it has some issue..

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 2 Oct 2019, 11:33 last edited by mrjj 10 Feb 2019, 11:34
                    #16

                    @RAJ-Dalsaniya

                    What types of issues ?
                    It is extremely hard to help when you do not describe
                    what happens,
                    what is wrong,
                    What do you see on screen after key pressed.

                    make sure you have valid index (i)

                     int maxSize = filenames.size() - 1;
                        // checks to make it round trip / avoid crashing
                        if (i > maxSize) { i = 0; }
                        if (i < 0 ) { i = maxSize; }
                    
                        if (i <= maxSize && i >= 0) {
                            ui->label->setPixmap(filenames.at(i));
                        }
                    
                    
                    R 1 Reply Last reply 2 Oct 2019, 11:41
                    0
                    • M mrjj
                      2 Oct 2019, 11:33

                      @RAJ-Dalsaniya

                      What types of issues ?
                      It is extremely hard to help when you do not describe
                      what happens,
                      what is wrong,
                      What do you see on screen after key pressed.

                      make sure you have valid index (i)

                       int maxSize = filenames.size() - 1;
                          // checks to make it round trip / avoid crashing
                          if (i > maxSize) { i = 0; }
                          if (i < 0 ) { i = maxSize; }
                      
                          if (i <= maxSize && i >= 0) {
                              ui->label->setPixmap(filenames.at(i));
                          }
                      
                      
                      R Offline
                      R Offline
                      RAJ Dalsaniya
                      wrote on 2 Oct 2019, 11:41 last edited by RAJ Dalsaniya 10 Feb 2019, 11:55
                      #17

                      @mrjj When I press key it change I value but it doesn't show picture that available in resource file. Problem is lable don't show picture from list. Can you just check what I write to add all links in filenames is right or not?

                      M 1 Reply Last reply 2 Oct 2019, 11:57
                      0
                      • R RAJ Dalsaniya
                        2 Oct 2019, 11:41

                        @mrjj When I press key it change I value but it doesn't show picture that available in resource file. Problem is lable don't show picture from list. Can you just check what I write to add all links in filenames is right or not?

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 2 Oct 2019, 11:57 last edited by
                        #18

                        @RAJ-Dalsaniya

                        Hi, find the image file in the project tree to the left side
                        then right-click it and see the correct path there. then check
                        what you add to list.

                        alt text

                        R 1 Reply Last reply 2 Oct 2019, 12:02
                        2
                        • M mrjj
                          2 Oct 2019, 11:57

                          @RAJ-Dalsaniya

                          Hi, find the image file in the project tree to the left side
                          then right-click it and see the correct path there. then check
                          what you add to list.

                          alt text

                          R Offline
                          R Offline
                          RAJ Dalsaniya
                          wrote on 2 Oct 2019, 12:02 last edited by
                          #19

                          @mrjj Thank you so much now it works totally fine .Thank you for your help

                          M 1 Reply Last reply 2 Oct 2019, 12:04
                          1
                          • R RAJ Dalsaniya
                            2 Oct 2019, 12:02

                            @mrjj Thank you so much now it works totally fine .Thank you for your help

                            M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 2 Oct 2019, 12:04 last edited by
                            #20

                            @RAJ-Dalsaniya
                            Super to hear \o/
                            Please mark as solved using the Topic Tool button at first post :)

                            1 Reply Last reply
                            1

                            17/20

                            2 Oct 2019, 11:41

                            • Login

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