Support_for_Coding_a_Picture_Viewer_(like_Flip-Flop)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Support_for_Coding_a_Picture_Viewer_(like_Flip-Flop)

  1. #1
    Join Date
    Apr 2017
    Posts
    6

    Support_for_Coding_a_Picture_Viewer_(like_Flip-Flop)

    Hello,
    I need support regarding the following code. There are some problems which do not work properly.

    Thank you in advance,

    The Task is :
    Please prepare a program which shows for a picture presentation. It should be loaded two different pictures, which
    should be shown each for five seconds (like a flip-flop).
    After start the program this should be work automatically. The pictures could be directly given which your own path.
    Additionally the program should be able with a "end" button.

    What doenst work properly :
    I had tried to to load the two pictures and and let them show for each of 5 sec. with a Timer.
    This doesnt work directly as it should be and I have to use the QMessageBox Button each time and push it.
    I think there is a logical failure or failures in it.

    The "bildbetrachter.cpp" file :
    ------------------------------------------------------
    Code:
    //die Header-Dateien einbinden
    #include "bildbetrachter.h"
    #include <QPixmap>
    #include <QMessageBox>
    #include <QFileDialog>
    #include <QDateTime>
    #include <QMouseEvent>
    #include <QLCDNumber>
    
    //der Konstruktor
    Bildbetrachter::Bildbetrachter()
    {
        //die Größe und den Titel setzen
        resize(380,400);
        setWindowTitle("Bildbetrachter");
    
        //den Timer für Bild1 erzeugen
        timerZeit = new QTimer(); //Bild1
        //das Signal timeout des Timers mit dem Slot verbinden
        QObject::connect(timerZeit, SIGNAL(timeout()), this, SLOT(timerZeitSlot())); //Bild1
    
        //den Timer für Bild2 erzeugen
        timerDatum = new QTimer(); //Bild2
        QObject::connect(timerDatum, SIGNAL(timeout()), this, SLOT(timerDatumSlot()));//Bild2
    
        bildLabel1 = new QLabel(this);
        bildLabel1->setGeometry(10, 10, 10, 10);
    
        bildLabel2 = new QLabel(this);
        bildLabel2->setGeometry(10, 10, 10, 10);
    
        //der Programmstart-Button um die Bilder jeweils für 5 Sek.anzuzeigen
        startButton = new QPushButton(this);
        startButton->setGeometry(250, 10, 100, 30);
        startButton->setText("Programmstart");
        QObject::connect(startButton, SIGNAL(clicked()), this, SLOT(timerZeitSlot()));
    
        //der Beenden-Button
        beendenButton = new QPushButton(this);
        beendenButton->setGeometry(250, 45, 100, 30);
        beendenButton->setText("Beenden");
        QObject::connect(beendenButton, SIGNAL(clicked()), this, SLOT(close()));
    
    }
    
    
    //die Methode für die Anzeige - Bild1
    void Bildbetrachter::timerZeitSlot() //Bild1
    {
        timerZeit->start(5000);
        //das Bild1 anzeigen
        zeigeBild1();
    
    }
    
    //die Methode für den Timer des Datums
    void Bildbetrachter::timerDatumSlot()
    {
        //die Methode stopDatum() aufrufen
        stopDatum();
    
    }
    
    
    void Bildbetrachter::zeigeBild1()
    {
        QPixmap bild1;
    
        if (timerZeit->isActive()==false)
            return;
        else
        {
        bild1.load("C:/Qt/Bilder/1.jpg");
        //die Größe wird dabei an die Breite 200 angepasst
        bild1 = bild1.scaledToWidth(200);
        //im Label anzeigen
        bildLabel1->setPixmap(bild1);
        //die Größe des Labels an die Größe des Bildes anpassen
        bildLabel1->resize(bild1.size());
        QMessageBox::information(this,"1","1");
    
        stopUhrzeit();
        }
    
    }
    
    //die Methode zeigeDatum()
    void Bildbetrachter::zeigeBild2() //Bild2
    {
        QPixmap bild2;
    
        if (timerDatum->isActive()==false)
        {stopDatum();
            return;
        }
        else
        {
        if (timerDatum->isActive()==true)
            {
        bild2.load("C:/Qt/Bilder/2.jpg");
        //die Größe wird dabei an die Breite 200 angepasst
        bild2 = bild2.scaledToWidth(200);
        //im Label anzeigen
        bildLabel2->setPixmap(bild2);
        //die Größe des Labels an die Größe des Bildes anpassen
        bildLabel2->resize(bild2.size());
        QMessageBox::information(this,"2","Bild2");
    
    
           }
        }
    
    }
    
    
    //die Methode stopUhrzeit()- Bild1 stoppen
    void Bildbetrachter::stopUhrzeit() //Bild1
    {
        //den Timer für Bild-1 anhalten
        timerZeit->stop(); //Bild1
        bildLabel1->clear();
        //den Timer für Bild-2 starten
        timerDatum->start(5000); //Bild2
        //Bild-2 Anzeige;
        zeigeBild2(); //Bild2 anzeigen
    }
    
    
    //die Methode stopDatum()
    void Bildbetrachter::stopDatum() //Bild2
    {
        //QMessageBox::information(this,"2","Bild2");
    
        //den Timer für Bild-2 anhalten
        timerDatum->stop(); //Bild2
        bildLabel2->clear();
        //den Timer für Bild-2 starten
        timerZeit->start(5000); //Bild1
        //Bild-1 Anzeige;
        zeigeBild1(); //Bild1 anzeigen
    }
    ----------------------------------------------------------------
    The Header File "bildbetrachter.h"
    Code:
    #ifndef BILDBETRACHTER_H
    #define BILDBETRACHTER_H
    
    //die Header-Dateien einbinden
    #include <QWidget>
    #include <QLabel>
    #include <QLineEdit>
    #include <QPushButton>
    #include <QLCDNumber>
    #include <QTimer>
    #include <QMouseEvent>
    #include <QDateTime>
    
    //oder auch
    //#include <QtWidgets>
    
    //unsere eigene Klasse erbt von QWidget
    class Bildbetrachter : public QWidget
    {
        //das Makro Q_OBJECT
        Q_OBJECT
        public:
        //der Konstruktor
        Bildbetrachter();
    
        //die Methoden und Attribute
        private:
            void zeigeUhrzeit(); //Bild1
            void zeigeDatum();   //Bild2
    
            void stopUhrzeit();  //Bild1
            void stopDatum();    //Bild2
    
    
            bool doppelpunkt;
            //der erste Timer
            QTimer* timerZeit;   //Bild1
            //der zweite Timer
            QTimer* timerDatum;  //Bild2
    
    
        //die Slots
        public slots:
            //void oeffneBilddatei();
            //void waehleDateiAus();
              void zeigeBild1();
              void zeigeBild2();
    
        private slots:
        //die Methode für den ersten Timer
              void timerZeitSlot();
        //die Methode für den zweiten Timer
              void timerDatumSlot();
    
    
        private:
            //die Attribute für die Widgets
            QLCDNumber *lcdnumber;
            QLabel* einLabel, *bildLabel1,*bildLabel2;
            QLineEdit* eingabeZeile;
            QPushButton* oeffnenButton, *beendenButton, *startButton,*auswaehlenButton;
    };
    #endif
    -------------------------------------------------------
    The main.cpp file
    Code:
    #include <QApplication>
    #include "bildbetrachter.h"
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
        //das Haupt-Widget erzeugen und anzeigen
        Bildbetrachter* betrachter = new Bildbetrachter();
        betrachter->show();
    
        return app.exec();
    }
    --------------------------------------------------------
    Last edited by 2kaud; July 6th, 2017 at 04:23 AM. Reason: Added code tags

  2. #2
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,835

    Re: Support_for_Coding_a_Picture_Viewer_(like_Flip-Flop)

    When posting code, please use code tags so that the code is readable. Go Advanced, select the formatted code and click '#'.

    Sorry I can't help as this uses QT which I don't use.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.4.4)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)