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

Thread: QLabel QPixmap change

  1. #1
    Join Date
    Jan 2025
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QLabel QPixmap change

    hello, sorry, I'm French so I'm talking with the translator, I want to change the image of a label based on a bool which is elsewhere in my program.
    how can I do it???

    THANKS

    mainwindow.cpp
    Qt Code:
    1. m_mainwindowThread.m_label = new QLabel(m_window);
    2. m_mainwindowThread.afficheLabelArret();
    To copy to clipboard, switch view to plain text mode 

    thread.h
    Qt Code:
    1. QLabel *m_label;
    2. void afficheLabelArret();
    To copy to clipboard, switch view to plain text mode 

    thread.cpp
    Qt Code:
    1. void Thread::afficheLabelArret()
    2. {
    3. if (m_threadGainable.labelModeFroid == true) {
    4. m_label ->setPixmap(QPixmap("/home/ludo/Qt/test2/build/images/froid.jpg"));
    5. else if (m_threadGainable.labelModeChauffage == true) {
    6. m_label ->setPixmap(QPixmap("/home/ludo/Qt/test2/build/images/chauffage.jpg"));
    7. } else {
    8. m_label ->setPixmap(QPixmap("/home/ludo/Qt/test2/build/images/abigael.jpg"));
    9. }
    10. }
    11.  
    12. void Thread::run()
    13. {
    14. while (1) {
    15. afficheLabelArret();
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    I have segfault randomly

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,287
    Thanks
    310
    Thanked 868 Times in 855 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLabel QPixmap change

    You cannot directly change something in the GUI thread from a different thread. The reason you are getting a segfault is probably because the GUI thread and your "Thread" are not synchronized.

    The correct way to do it is to emit a signal from your Thread that is connected to a slot in MainWindow.

    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. // ...
    4. private slots:
    5. void onChangeLabel( int mode );
    6.  
    7. private:
    8. QLabel * m_label;
    9. };
    10.  
    11. class Thread : public QThread
    12. {
    13. // ...
    14. signals:
    15. void changeLabel(int mode );
    16. };
    17.  
    18. MainWindow::MainWindow( QWidget * parent )
    19. : Qwidget( parent )
    20. {
    21. // ...
    22. connect( m_mainwindowThread, &Thread::changeLabel, this, &MainWindow::onChangeLabel );
    23. }
    24.  
    25. void Thread::afficheLabelArret()
    26. {
    27. if (m_threadGainable.labelModeFroid == true) {
    28. emit changeLabel( 0 );
    29. else if (m_threadGainable.labelModeChauffage == true) {
    30. emit changeLabel( 1 );
    31. } else {
    32. emit changeLabel( 2 );
    33. }
    34.  
    35. void MainWindow::onChangeLabel( int mode )
    36. {
    37. switch( mode )
    38. {
    39. case 0:
    40. m_label ->setPixmap(QPixmap("/home/ludo/Qt/test2/build/images/froid.jpg"));
    41. break;
    42.  
    43. case 1:
    44. m_label ->setPixmap(QPixmap("/home/ludo/Qt/test2/build/images/chauffage.jpg"));
    45. break;
    46.  
    47. default:
    48. m_label ->setPixmap(QPixmap("/home/ludo/Qt/test2/build/images/abigael.jpg"));
    49. break;
    50. }
    51. }
    To copy to clipboard, switch view to plain text mode 

    The signal / slot mechanism will make sure that the inter-thread call is synchronized correctly.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jan 2025
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLabel QPixmap change

    ok I'm going to try this tomorrow, do you have a coding organization for:
    I want to manage a heating system with an rpi (raspberry) in c++! and use a graphical interface depending on the states of the GPIOs. go through temperatures.

    if this speaks to you. Thank you in advance for giving me time to this project.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,287
    Thanks
    310
    Thanked 868 Times in 855 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLabel QPixmap change

    I want to manage a heating system with an rpi (raspberry) in c++! and use a graphical interface depending on the states of the GPIOs. go through temperature
    I have not made such a project, but if you Google for "Raspberry Pi thermostat" you might find some good information.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Jan 2025
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLabel QPixmap change

    so I tried but I get errors
    /home/ludo/Qt/test2/mainwindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)':
    /home/ludo/Qt/test2/mainwindow.cpp:17:86: error: no matching function for call to 'MainWindow::connect(Thread&, void (Thread::*)(int), MainWindow*, void (MainWindow::*)(int))'
    17 | inwindowThread,&Thread::changeLabel, this, &MainWindow:nChangeLabel);
    | ^

    In file included from /usr/include/aarch64-linux-gnu/qt5/QtCore/qabstractanimation.h:43,
    from /usr/include/aarch64-linux-gnu/qt5/QtCore/QtCore:6,
    from /usr/include/aarch64-linux-gnu/qt5/QtWidgets/QtWidgetsDepends:3,
    from /usr/include/aarch64-linux-gnu/qt5/QtWidgets/QtWidgets:3,
    from /home/ludo/Qt/test2/mainwindow.h:3,
    from /home/ludo/Qt/test2/mainwindow.cpp:1:
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:222:36: note: candidate: 'static QMetaObject::Connection QObject::connect(const QObject*, const char*, const QObject*, const char*, Qt::ConnectionType)'
    222 | static QMetaObject::Connection connect(const QObject *sender, const char *signal,
    | ^~~~~~~
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:222:59: note: no known conversion for argument 1 from 'Thread' to 'const QObject*'
    222 | static QMetaObject::Connection connect(const QObject *sender, const char *signal,
    | ~~~~~~~~~~~~~~~^~~~~~
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:225:36: note: candidate: 'static QMetaObject::Connection QObject::connect(const QObject*, const QMetaMethod&, const QObject*, const QMetaMethod&, Qt::ConnectionType)'
    225 | static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal,
    | ^~~~~~~
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:225:59: note: no known conversion for argument 1 from 'Thread' to 'const QObject*'
    225 | static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal,
    | ~~~~~~~~~~~~~~~^~~~~~
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:481:32: note: candidate: 'QMetaObject::Connection QObject::connect(const QObject*, const char*, const char*, Qt::ConnectionType) const'
    481 | inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
    | ^~~~~~~
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:481:64: note: no known conversion for argument 1 from 'Thread' to 'const QObject*'
    481 | ine QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
    | ~~~~~~~~~~~~~~~^~~~~~~

    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:242:43: note: candidate: 'static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType) [with Func1 = void (Thread::*)(int); Func2 = void (MainWindow::*)(int); typename QtPrivate::FunctionPointer<Func>::Object = Thread; typename QtPrivate::FunctionPointer<Func2>::Object = MainWindow]'
    242 | static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
    | ^~~~~~~
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:242:109: note: no known conversion for argument 1 from 'Thread' to 'const Object*' {aka 'const Thread*'}
    242 | t(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal,
    | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~^~~~~~

    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:274:13: note: candidate: 'template<class Func1, class Func2> static typename std::enable_if<((int)(QtPrivate::FunctionPointer<F unc2>::ArgumentCount) >= 0), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)'
    274 | connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
    | ^~~~~~~
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:274:13: note: template argument deduction/substitution failed:
    /home/ludo/Qt/test2/mainwindow.cpp:17:86: note: candidate expects 3 arguments, 4 provided
    17 | inwindowThread,&Thread::changeLabel, this, &MainWindow:nChangeLabel);
    | ^

    In file included from /usr/include/aarch64-linux-gnu/qt5/QtCore/qabstractanimation.h:43,
    from /usr/include/aarch64-linux-gnu/qt5/QtCore/QtCore:6,
    from /usr/include/aarch64-linux-gnu/qt5/QtWidgets/QtWidgetsDepends:3,
    from /usr/include/aarch64-linux-gnu/qt5/QtWidgets/QtWidgets:3,
    from /home/ludo/Qt/test2/mainwindow.h:3,
    from /home/ludo/Qt/test2/mainwindow.cpp:1:
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:283:13: note: candidate: 'template<class Func1, class Func2> static typename std::enable_if<(((int)(QtPrivate::FunctionPointer< Func2>::ArgumentCount) >= 0) && (! QtPrivate::FunctionPointer<Func2>::IsPointerToMemb erFunction)), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType)'
    283 | connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
    | ^~~~~~~
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:283:13: note: template argument deduction/substitution failed:
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename std::enable_if<(((int)(QtPrivate::FunctionPointer< Func2>::ArgumentCount) >= 0) && (! QtPrivate::FunctionPointer<Func2>::IsPointerToMemb erFunction)), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType) [with Func1 = void (Thread::*)(int); Func2 = void (MainWindow::*)(int)]':
    /home/ludo/Qt/test2/mainwindow.cpp:17:86: required from here
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:283:13: error: no type named 'type' in 'struct std::enable_if<false, QMetaObject::Connection>'
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:314:13: note: candidate: 'template<class Func1, class Func2> static typename std::enable_if<(QtPrivate::FunctionPointer<Func2>: :ArgumentCount == -1), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, Func2)'
    314 | connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot)
    | ^~~~~~~
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:314:13: note: template argument deduction/substitution failed:
    /home/ludo/Qt/test2/mainwindow.cpp:17:86: note: candidate expects 3 arguments, 4 provided
    17 | inwindowThread,&Thread::changeLabel, this, &MainWindow:nChangeLabel);
    | ^

    In file included from /usr/include/aarch64-linux-gnu/qt5/QtCore/qabstractanimation.h:43,
    from /usr/include/aarch64-linux-gnu/qt5/QtCore/QtCore:6,
    from /usr/include/aarch64-linux-gnu/qt5/QtWidgets/QtWidgetsDepends:3,
    from /usr/include/aarch64-linux-gnu/qt5/QtWidgets/QtWidgets:3,
    from /home/ludo/Qt/test2/mainwindow.h:3,
    from /home/ludo/Qt/test2/mainwindow.cpp:1:
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:322:13: note: candidate: 'template<class Func1, class Func2> static typename std::enable_if<(QtPrivate::FunctionPointer<Func2>: :ArgumentCount == -1), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType)'
    322 | connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
    | ^~~~~~~
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:322:13: note: template argument deduction/substitution failed:
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h: In substitution of 'template<class Func1, class Func2> static typename std::enable_if<(QtPrivate::FunctionPointer<Func2>: :ArgumentCount == -1), QMetaObject::Connection>::type QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const QObject*, Func2, Qt::ConnectionType) [with Func1 = void (Thread::*)(int); Func2 = void (MainWindow::*)(int)]':
    /home/ludo/Qt/test2/mainwindow.cpp:17:86: required from here
    /usr/include/aarch64-linux-gnu/qt5/QtCore/qobject.h:322:13: error: no type named 'type' in 'struct std::enable_if<false, QMetaObject::Connection>'
    make[2]: *** [CMakeFiles/test.dir/build.make:108 : CMakeFiles/test.dir/mainwindow.cpp.o] Erreur 1
    make[1]: *** [CMakeFiles/Makefile2:96 : CMakeFiles/test.dir/all] Erreur 2
    make: *** [Makefile:103 : all] Erreur 2

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3. #include <QtWidgets>
    4.  
    5. #include "thread.h"
    6. #include "affichecons.h"
    7.  
    8. class MainWindow: public QWidget
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. MainWindow(QWidget *parent = nullptr);
    14.  
    15. void readTemps();
    16.  
    17. private slots:
    18. void onChangeLabel(int mode);
    19.  
    20. private:
    21. Thread m_mainwindowThread;
    22.  
    23. AfficheCons *m_afficheCons;
    24.  
    25. QLabel *m_label;
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. MainWindow::MainWindow(QWidget *parent)
    4. :QWidget (parent)
    5. {
    6. qDebug() << "mainwindow";
    7.  
    8. m_mainwindowThread.start();
    9.  
    10. m_window = new QWidget;
    11. m_window ->setFixedSize(1920,1080);
    12. m_window ->setWindowTitle("Gainable");
    13. adjustSize();
    14.  
    15. //m_mainwindowThread.m_label = new QLabel(m_window);
    16. //m_mainwindowThread.afficheLabelArret();
    17. connect(m_mainwindowThread,&Thread::changeLabel, this, &MainWindow::onChangeLabel);
    18.  
    19. void MainWindow::onChangeLabel(int mode)
    20. {
    21. switch(mode)
    22. {
    23. case 0:
    24.  
    25. m_label ->setPixmap(QPixmap("/home/ludo/Qt/test2/build/images/froid.jpg"));
    26.  
    27. break;
    28.  
    29. case 1:
    30.  
    31. m_label ->setPixmap(QPixmap("/home/ludo/Qt/test2/build/images/chauffage.jpg"));
    32.  
    33. break;
    34.  
    35. default:
    36.  
    37. m_label ->setPixmap(QPixmap("/home/ludo/Qt/test2/build/images/abigael.jpg"));
    38.  
    39. break;
    40.  
    41. }
    42. }
    To copy to clipboard, switch view to plain text mode 
    #ifndef THREAD_H
    #define THREAD_H
    #include <QtWidgets>
    #include <QThread>

    #include "sondes.h"
    #include "parametres.h"
    #include "gainable.h"
    #include "hysteresisvitesses.h"

    class Thread: public QThread
    {
    Q_OBJECT

    public:
    Thread();
    signals:
    void changeLabel(int mode);

    };

    Qt Code:
    1. #include "thread.h"
    2.  
    3. Thread::Thread()
    4. {
    5. qDebug() << "Thread";
    6.  
    7. m_threadParametres = new Parametres(QString("settings/parametres.ini"), QSettings::IniFormat);
    8. }
    9.  
    10. void Thread::lectureSondes()
    11. {
    12. m_threadParametres ->lireTemperatures();
    13.  
    14. m_tempExtLue ->display(m_threadParametres ->temperatureExt);
    15. m_tempUnitExtLue ->display(m_threadParametres ->temperatureUnitExt);
    16. m_tempEcExtLue ->display(m_threadParametres ->temperatureEcExt);
    17. m_tempUnitIntLue ->display(m_threadParametres ->temperatureUnitInt);
    18. m_tempEcIntLue ->display(m_threadParametres ->temperatureEcInt);
    19. }
    20.  
    21. void Thread::afficheLabelArret()
    22. {
    23. if (m_threadGainable.labelModeFroid == true) {
    24. emit changeLabel( 0 );
    25. } else if (m_threadGainable.labelModeChauffage == true) {
    26. emit changeLabel( 1 );
    27. } else {
    28. emit changeLabel( 2 );
    29. }
    30. //m_label ->setPixmap(QPixmap("/home/ludo/Qt/test2/build/images/abigael.jpg"));
    31. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    517
    Thanks
    12
    Thanked 77 Times in 75 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLabel QPixmap change

    Hi, the first parameter to connect() needs to be a pointer, so
    connect(&m_mainwindowThread,...
    should work.

    Ginsengelf

  7. #7
    Join Date
    Jan 2025
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLabel QPixmap change

    Quote Originally Posted by Ginsengelf View Post
    Hi, the first parameter to connect() needs to be a pointer, so
    connect(&m_mainwindowThread,...
    should work.

    Ginsengelf
    thank you very much, it works.

    but connecting QPushButtons looks like this.
    connect(m_stop,&QPushButton::clicked,m_stop,[this](){stopGainable();});

    yours is like this
    connect(&m_mainwindowThread, &Thread::changeLabel, this, &MainWindow:nChangeLabel);

    Does that change anything? if you could enlighten me!!

    and for my animated gifs, the way I do it suits you??

    mainwindow cpp
    Qt Code:
    1. m_mainwindowThread.m_labelGifChauffe = new QLabel(m_window);
    2. m_mainwindowThread.afficheGifChauffe();
    To copy to clipboard, switch view to plain text mode 

    thread h
    Qt Code:
    1. QLabel *m_labelGifChauffe;
    2. QMovie *m_gifChauffe;
    3. void afficheGifChauffe();
    4. void Thread::afficheGifChauffe();
    To copy to clipboard, switch view to plain text mode 

    thread cpp
    Qt Code:
    1. {
    2. m_labelGifChauffe ->setGeometry(1220,840,200,200);
    3. m_gifChauffe = new QMovie("/home/ludo/Qt/test2/build/gif/chauffage.gif");
    4. m_labelGifChauffe ->setMovie(m_gifChauffe);
    5. m_labelGifChauffe ->hide();
    6. m_gifChauffe ->start();
    7. }
    8.  
    9. void Thread::affichageChauffage()
    10. {
    11. if (m_threadGainable.gifChauffage == true) {
    12. m_labelGifChauffe ->show();
    13. } else {
    14. m_labelGifChauffe ->hide();
    15. }
    16. }
    17.  
    18. void Thread::run()
    19. {
    20. while(1) {
    21. affichageChauffage();
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,287
    Thanks
    310
    Thanked 868 Times in 855 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLabel QPixmap change

    connect(m_stop,&QPushButton::clicked,m_stop,[this](){stopGainable();});
    This code is saying: "Connect the clicked() signal from the QPushButton named 'm_stop' to a lambda of the same QPushButton which executes the method 'stopGainable()'".

    I am not really sure what you are trying to do with this code. I don't see a method named "stopGainable()" anywhere. I assume you didn't post all of your code.

    If "stopGainable()" is a slot of MainWindow, and you are calling this connect() method from inside of MainWindow, then the correct code is:

    Qt Code:
    1. connect( m_stop, &QPushBotton::clicked, this, &MainWindow::stopGainable );
    To copy to clipboard, switch view to plain text mode 

    If "stopGainable()" is a method of the Thread class, then the correct code is:

    Qt Code:
    1. connect( m_stop, &QPushButton::clicked, &m_mainwindowThread, &Thread::stopGainable );
    To copy to clipboard, switch view to plain text mode 

    Instead of making life more complicated and harder to debug by using lambda expressions, add signals and slots as member functions in your classes. This will let you easily set breakpoints inside them so you can see what is happening. In this case, using lambda expressions is not helpful and makes it much more difficult to follow the execution of your code.

    Qt Code:
    1. void Thread::affichageChauffage()
    2. {
    3. if (m_threadGainable.gifChauffage == true) {
    4. m_labelGifChauffe ->show();
    5. } else {
    6. m_labelGifChauffe ->hide();
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    This code will not work, and will cause another segfault.

    As I said in an earlier post, you cannot execute any GUI code anywhere except in the main GUI thread (in your case, the one that owns MainWindow). ALL GUI code and ALL GUI widgets must be created in and owned by the GUI thread. The only way you can control them from a non-GUI thread is to use a signal / slot connection from the non-GUI thread to the GUI thread, as I also showed earlier.

    There can only be one GUI thread in an application.
    Last edited by d_stranz; 31st January 2025 at 18:20.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  9. #9
    Join Date
    Jan 2025
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLabel QPixmap change

    sorry, I'll show you:

    mainwindow h
    Qt Code:
    1. QPushButton *m_stop;
    2. void stopGainable();
    To copy to clipboard, switch view to plain text mode 

    mainwindow cpp
    Qt Code:
    1. m_stop = new QPushButton("Stop ??",m_window);
    2. m_stop ->setGeometry(1600,900,240,95);
    3. m_stop ->setStyleSheet("font-size: 30px;background-color: red");
    4.  
    5. m_stop ->show();connect(m_stop,&QPushButton::clicked,m_stop,[this](){stopGainable();});
    6.  
    7. void MainWindow::stopGainable()
    8. {
    9. qDebug() << "arret Gainable";
    10. m_stop ->hide();
    11. m_marche ->show();
    12. m_mainwindowThread.departGainable = false;
    13. }
    To copy to clipboard, switch view to plain text mode 

    thread h
    Qt Code:
    1. bool departGainable = true;
    To copy to clipboard, switch view to plain text mode 


    thread cpp
    Qt Code:
    1. void Thread::run()
    2. {
    3. while(1) {
    4. if (departGainable == true) {
    5. affichageGifChauffe();
    6. ....
    7. } else {
    8. ....
    9. }
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 


    Added after 10 minutes:


    Quote Originally Posted by d_stranz View Post
    This code is saying: "Connect the clicked() signal from the QPushButton named 'm_stop' to a lambda of the same QPushButton which executes the method 'stopGainable()'".

    I am not really sure what you are trying to do with this code. I don't see a method named "stopGainable()" anywhere. I assume you didn't post all of your code.

    If "stopGainable()" is a slot of MainWindow, and you are calling this connect() method from inside of MainWindow, then the correct code is:

    Qt Code:
    1. connect( m_stop, &QPushBotton::clicked, this, &MainWindow::stopGainable );
    To copy to clipboard, switch view to plain text mode 

    If "stopGainable()" is a method of the Thread class, then the correct code is:

    Qt Code:
    1. connect( m_stop, &QPushButton::clicked, &m_mainwindowThread, &Thread::stopGainable );
    To copy to clipboard, switch view to plain text mode 

    Instead of making life more complicated and harder to debug by using lambda expressions, add signals and slots as member functions in your classes. This will let you easily set breakpoints inside them so you can see what is happening. In this case, using lambda expressions is not helpful and makes it much more difficult to follow the execution of your code.

    Qt Code:
    1. void Thread::affichageChauffage()
    2. {
    3. if (m_threadGainable.gifChauffage == true) {
    4. m_labelGifChauffe ->show();
    5. } else {
    6. m_labelGifChauffe ->hide();
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    This code will not work, and will cause another segfault.

    As I said in an earlier post, you cannot execute any GUI code anywhere except in the main GUI thread (in your case, the one that owns MainWindow). ALL GUI code and ALL GUI widgets must be created in and owned by the GUI thread. The only way you can control them from a non-GUI thread is to use a signal / slot connection from the non-GUI thread to the GUI thread, as I also showed earlier.

    There can only be one GUI thread in an application.

    ok thank you, it still worked (gifChuaffage), but it's true that from a moment on the animated gifs freeze, on the other hand without fault.

    great thank you for your time, it helps me a lot!

    Do you know the DS18B20 probes on RPI4 (raspberry)???


    Added after 13 minutes:


    thank you, thanks to you friends, I understand better!! I kiss you
    Last edited by ludoQtCreator; 31st January 2025 at 18:45.

  10. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,287
    Thanks
    310
    Thanked 868 Times in 855 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLabel QPixmap change

    connect(m_stop,&QPushButton::clicked,m_stop,[this](){stopGainable();});
    No. stopGainable() is a MainWindow method. It does not belong to m_stop. Do this:

    Qt Code:
    1. connect(m_stop, &QPushButton::clicked, this, &MainWindow::stopGainable );
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void MainWindow::stopGainable()
    2. {
    3. qDebug() << "arret Gainable";
    4. m_stop ->hide();
    5. m_marche ->show();
    6. m_mainwindowThread.departGainable = false; <--- No. You cannot do this.
    7. }
    To copy to clipboard, switch view to plain text mode 

    You cannot directly change a member variable in a different thread. This will cause a segfault. You must use a signal / slot connection in Qt:

    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. // ...
    4.  
    5. signals:
    6. void changeGainableState( bool bState );
    7.  
    8. };
    9.  
    10. class Thread : public QThread
    11. {
    12. // ...
    13.  
    14. public slots:
    15. void onChangeGainableState( bool bState );
    16.  
    17. };
    18.  
    19. MainWindow::MainWindow( ... )
    20. {
    21. // ...
    22. connect(m_stop, &QPushButton::clicked, this, &MainWindow::stopGainable );
    23. connect(m_marche, &QPushButton::clicked, this, &MainWindow::startGainable );
    24. connect( this, &MainWindow::changeGainableState, &m_mainwindowThread, &Thread::onChangeGainableState );
    25. // ...
    26. }
    27.  
    28. void MainWindow::stopGainable()
    29. {
    30. qDebug() << "arret Gainable";
    31. m_stop ->hide();
    32. m_marche ->show();
    33. emit changeGainableState( false );
    34. }
    35.  
    36. void MainWindow::startGainable()
    37. {
    38. qDebug() << "start Gainable";
    39. m_marche ->hide();
    40. m_stop ->show();
    41. emit changeGainableState( true );
    42. }
    43.  
    44. void Thread::onChangeGainableState( bool bState )
    45. {
    46. departGainable = state;
    47. }
    48.  
    49. void Thread::run()
    50. {
    51. while(1) {
    52. if (departGainable == true) {
    53. affichageGifChauffe();
    54. ....
    55. } else {
    56. ....
    57. }
    58. QCoreApplication::processEvents(); // MUST do this otherwise your thread cannot process signals from MainWindow
    59. }
    60. }
    To copy to clipboard, switch view to plain text mode 

    You must add a call to QCoreApplication::processEvents() inside of your thread's run() method, other wise the infinite loop will block the thread and prevent any signals from being handled.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  11. #11
    Join Date
    Jan 2025
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLabel QPixmap change

    thank you very much, there are a lot of mistakes I made; if you want I have a link where I posted my code from the very beginning. You're going to run away!

    https://github.com/ludoiphone/GainableRaspberry

  12. The following user says thank you to ludoQtCreator for this useful post:

    d_stranz (31st January 2025)

  13. #12
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,287
    Thanks
    310
    Thanked 868 Times in 855 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLabel QPixmap change

    I have not used Raspberry Pi for any automation projects, only for things like a CUPS print server and Kodi movie server. Mostly I am using Arduino Uno for robotics and other projects.

    Good luck!
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  14. #13
    Join Date
    Jan 2025
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLabel QPixmap change

    Qt Code:
    1. void Thread::run()
    2. {
    3. while(1) {
    4. if (departGainable == true) {
    5. affichageGifChauffe();
    6. ....
    7. } else {
    8. ....
    9. }
    10. QCoreApplication::processEvents(); // MUST do this otherwise your thread cannot process signals from MainWindow
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

    You must add a call to QCoreApplication::processEvents() inside of your thread's run() method, other wise the infinite loop will block the thread and prevent any signals from being handled.


    works perfectly

    on the other hand I try with my Anim Gifs, I can't, I suppose I have to do like "gainable(true);
    ???? THANKS
    Last edited by d_stranz; 2nd February 2025 at 17:29. Reason: missing [code], [quote] tags

  15. #14
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,287
    Thanks
    310
    Thanked 868 Times in 855 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLabel QPixmap change

    on the other hand I try with my Anim Gifs, I can't, I suppose I have to do like "gainable(true);
    Your GIFs are part of the GUI, so you must control them on the GUI side. You cannot directly control them from the Thread side. So if you have a change on the Thread side that should cause the GIF to change on the GUI side, then the best way is through a signal / slot connection.

    Do not try to directly change the value of any variable across a thread boundary (like between the GUI and Thread threads). It might work sometimes, but eventually the timing will be wrong and it will cause a crash.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  16. #15
    Join Date
    Jan 2025
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLabel QPixmap change

    ok, so I did:

    mainwindow h

    Qt Code:
    1. public slots:
    2. void changeLabel(int m_mode);
    3.  
    4. void affichageGifsNettoyageFiltre(int m_gifsFiltre);
    5.  
    6. void affichageGifsVentInt(int m_gifsVentilationInt);
    7. void affichageGifsVentExt(int m_gifsVentilationExt);
    To copy to clipboard, switch view to plain text mode 

    mainwindow cpp

    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. MainWindow::MainWindow(QWidget *parent)
    4. :QWidget (parent)
    5. {
    6.  
    7. m_labelGifNettoyageEnCours = new QLabel(m_window);
    8. m_labelGifNettoyageEnCours ->setGeometry(720,300,480,480);
    9. m_movieGifNettoyageEnCours = new QMovie("/home/ludo/Qt/test2/build/gif/nettoyageEnCours.gif");
    10. m_labelGifNettoyageEnCours ->setMovie(m_movieGifNettoyageEnCours);
    11. m_movieGifNettoyageEnCours ->start();
    12. m_labelGifNettoyageFiltre = new QLabel(m_window);
    13. m_labelGifNettoyageFiltre ->setGeometry(20,840,200,200);
    14. m_movieGifNettoyageFiltre = new QMovie("/home/ludo/Qt/test2/build/gif/nettoyageFiltre.gif");
    15. m_labelGifNettoyageFiltre ->setMovie(m_movieGifNettoyageFiltre);
    16. m_movieGifNettoyageFiltre ->start();
    17. m_labelGifArretProgramme = new QLabel(m_window);
    18. m_labelGifArretProgramme ->setGeometry(720,300,480,480);
    19. m_movieGifArretProgramme = new QMovie("/home/ludo/Qt/test2/build/gif/arretProgrammeFiltre.gif");
    20. m_labelGifArretProgramme ->setMovie(m_movieGifArretProgramme);
    21. m_movieGifArretProgramme ->start();
    22.  
    23. m_labelGifVentInt = new QLabel(m_window);
    24. m_labelGifVentInt ->setGeometry(1105,845,200,200);
    25. m_movieGifVentInt = new QMovie("/home/ludo/Qt/test2/build/gif/ventilateurInt.gif");
    26. m_labelGifVentInt ->setMovie(m_movieGifVentInt);
    27. m_movieGifVentInt ->start();
    28. m_labelGifVitesse1Int = new QLabel(m_window);
    29. m_labelGifVitesse1Int ->setGeometry(1040,900,60,60);
    30. m_movieGifVitesse1Int = new QMovie("/home/ludo/Qt/test2/build/gif/vitesse1.gif");
    31. m_labelGifVitesse1Int ->setMovie(m_movieGifVitesse1Int);
    32. m_movieGifVitesse1Int ->start();
    33. m_labelGifVitesse4Int = new QLabel(m_window);
    34. m_labelGifVitesse4Int ->setGeometry(1040,900,60,60);
    35. m_movieGifVitesse4Int = new QMovie("/home/ludo/Qt/test2/build/gif/vitesse4.gif");
    36. m_labelGifVitesse4Int ->setMovie(m_movieGifVitesse4Int);
    37. m_movieGifVitesse4Int ->start();
    38.  
    39. m_labelGifVentExt = new QLabel(m_window);
    40. m_labelGifVentExt ->setGeometry(910,830,200,200);
    41. m_movieGifVentExt = new QMovie("/home/ludo/Qt/test2/build/gif/ventilateurExt.gif");
    42. m_labelGifVentExt ->setMovie(m_movieGifVentExt);
    43. m_movieGifVentExt ->start();
    44. m_labelGifVitesse1Ext = new QLabel(m_window);
    45. m_labelGifVitesse1Ext ->setGeometry(860,900,60,60);
    46. m_movieGifVitesse1Ext = new QMovie("/home/ludo/Qt/test2/build/gif/vitesse1.gif");
    47. m_labelGifVitesse1Ext ->setMovie(m_movieGifVitesse1Ext);
    48. m_movieGifVitesse1Ext ->start();
    49. m_labelGifVitesse2Ext = new QLabel(m_window);
    50. m_labelGifVitesse2Ext ->setGeometry(860,900,60,60);
    51. m_movieGifVitesse2Ext = new QMovie("/home/ludo/Qt/test2/build/gif/vitesse2.gif");
    52. m_labelGifVitesse2Ext ->setMovie(m_movieGifVitesse2Ext);
    53. m_movieGifVitesse2Ext ->start();
    54.  
    55. m_labelGifFroid = new QLabel(m_window);
    56. m_labelGifFroid ->setGeometry(1210,845,200,200);
    57. m_movieGifFroid = new QMovie("/home/ludo/Qt/test2/build/gif/froid.gif");
    58. m_labelGifFroid ->setMovie(m_movieGifFroid);
    59. m_movieGifFroid ->start();
    60.  
    61. connect(&m_mainwindowThread, &Thread::afficheGifsFiltre, this, &MainWindow::affichageGifsNettoyageFiltre);
    62. affichageGifsNettoyageFiltre(4);
    63.  
    64. connect(&m_mainwindowThread, &Thread::afficheGifsVentInt, this, &MainWindow::affichageGifsVentInt);
    65. affichageGifsVentInt(2);
    66. connect(&m_mainwindowThread, &Thread::afficheGifsVentExt, this, &MainWindow::affichageGifsVentExt);
    67. affichageGifsVentExt(2);
    68.  
    69. connect(&m_mainwindowThread, &Thread::afficheGifComp, this, &MainWindow::affichageGifComp);
    70. affichageGifComp(1);
    71.  
    72. connect(this, &MainWindow::changeGainableState, &m_mainwindowThread, &Thread::onChangeGainableState);
    73.  
    74. connect(m_marche, &QPushButton::clicked, this, &MainWindow::reStartGainable);
    75. connect(m_consigne, &QPushButton::clicked, this, &MainWindow::afficheConsignes);
    76. connect(m_stop, &QPushButton::clicked, this, &MainWindow::stopGainable);
    77.  
    78. m_window->show();
    79. }
    80.  
    81.  
    82. void MainWindow::affichageGifsNettoyageFiltre(int m_gifsFiltre)
    83. {
    84. switch (m_gifsFiltre)
    85. {
    86. case 0:
    87.  
    88. m_labelGifArretProgramme ->show();
    89. m_labelGifNettoyageFiltre ->show();
    90.  
    91. break;
    92.  
    93. case 1:
    94.  
    95. m_labelGifArretProgramme ->hide();
    96. m_labelGifNettoyageFiltre ->hide();
    97. m_labelGifNettoyageEnCours ->show();
    98.  
    99. break;
    100.  
    101. case 2:
    102.  
    103. m_labelGifNettoyageFiltre ->show();
    104.  
    105. break;
    106.  
    107. case 3:
    108.  
    109. m_labelGifNettoyageEnCours ->hide();
    110.  
    111. break;
    112.  
    113. default:
    114.  
    115. m_labelGifNettoyageEnCours ->hide();
    116. m_labelGifArretProgramme ->hide();
    117. m_labelGifNettoyageFiltre ->hide();
    118.  
    119. break;
    120. }
    121. }
    122.  
    123. void MainWindow::affichageGifsVentInt(int m_gifsVentilationInt)
    124. {
    125. switch (m_gifsVentilationInt)
    126. {
    127. case 0:
    128.  
    129. m_labelGifVentInt ->show();
    130. m_labelGifVitesse1Int ->hide();
    131. m_labelGifVitesse4Int ->show();
    132.  
    133. break;
    134.  
    135. case 1:
    136.  
    137. m_labelGifVentInt ->show();
    138. m_labelGifVitesse1Int ->show();
    139. m_labelGifVitesse4Int ->hide();
    140.  
    141. break;
    142.  
    143. default:
    144.  
    145. m_labelGifVentInt ->hide();
    146. m_labelGifVitesse1Int ->hide();
    147. m_labelGifVitesse4Int ->hide();
    148.  
    149. break;
    150. }
    151. }
    152. void MainWindow::affichageGifsVentExt(int m_gifsVentilationExt)
    153. {
    154. switch (m_gifsVentilationExt)
    155. {
    156. case 0:
    157.  
    158. m_labelGifVentExt ->show();
    159. m_labelGifVitesse1Ext ->show();
    160. m_labelGifVitesse2Ext ->hide();
    161.  
    162. break;
    163.  
    164. case 1:
    165.  
    166. m_labelGifVentExt ->show();
    167. m_labelGifVitesse1Ext ->hide();
    168. m_labelGifVitesse2Ext ->show();
    169.  
    170. break;
    171.  
    172. default:
    173.  
    174. m_labelGifVentExt ->hide();
    175. m_labelGifVitesse1Ext ->hide();
    176. m_labelGifVitesse2Ext ->hide();
    177.  
    178. break;
    179. }
    180. }
    181.  
    182. void MainWindow::affichageGifComp(int m_gifCompresseur)
    183. {
    184. switch (m_gifCompresseur)
    185. {
    186. case 0:
    187.  
    188. m_labelGifFroid ->show();
    189.  
    190. break;
    191.  
    192. default:
    193.  
    194. m_labelGifFroid ->hide();
    195.  
    196. break;
    197. }
    198. }
    199.  
    200. void MainWindow::afficheConsignes()
    201. {
    202. qDebug() << "afficheConsignes";
    203. m_afficheCons = new AfficheCons();
    204. m_afficheCons ->readCons();
    205. }
    206.  
    207. void MainWindow::stopGainable()
    208. {
    209. qDebug() << "arret Gainable";
    210. m_stop ->hide();
    211. m_marche ->show();
    212. emit changeGainableState(false);
    213. }
    214.  
    215. void MainWindow::reStartGainable()
    216. {
    217. m_marche ->hide();
    218. m_stop ->show();
    219. emit changeGainableState(true);
    To copy to clipboard, switch view to plain text mode 

    thread h

    Qt Code:
    1. void changeLabel(int m_mode);
    2.  
    3. void affichageGifsNettoyageFiltre(int m_gifsFiltre);
    4.  
    5. void affichageGifsVentInt(int m_gifsVentilationInt);
    6. void affichageGifsVentExt(int m_gifsVentilationExt);
    7.  
    8. signals:
    9. void majLabel(int m_mode);
    10.  
    11. void afficheGifsFiltre(int m_gifsFiltre);
    12.  
    13. void afficheGifsVentInt(int m_gifsVentilationInt);
    14. void afficheGifsVentExt(int m_gifsVentilationExt);
    To copy to clipboard, switch view to plain text mode 

    thread cpp

    Qt Code:
    1. void Thread::afficheGifsNettoyageFiltre()
    2. {
    3. if (m_threadGainable.gifArretProgrammeFiltre == true) {
    4. emit afficheGifsFiltre(0);
    5. } else if (m_threadGainable.gifNettoyageFiltreEnCours == true) {
    6. emit afficheGifsFiltre(1);
    7. } else {
    8. if (m_threadGainable.gifNettoyageFiltre == true) {
    9. emit afficheGifsFiltre(2);
    10. } else {
    11. emit afficheGifsFiltre(3);
    12. }
    13. }
    14. }
    15.  
    16. void Thread::afficheGifsVentInterieur()
    17. {
    18. if (m_threadGainable.gifVentilation == true) {
    19. emit afficheGifsVentInt(0);// affiche grande vitesse
    20. } else {
    21. if (m_threadGainable.gifVentilationIntFr == true) {
    22. m_threadHysteresis.hysteresisTempVitesseIntFroid();
    23. if (m_threadHysteresis.tempVitIntFr == false) {
    24. emit afficheGifsVentInt(1); // petite vitesse si faux
    25. }else {
    26. emit afficheGifsVentInt(0);
    27. }
    28. } else {
    29. emit afficheGifsVentInt(2);
    30. }
    31. }
    32. }
    33.  
    34. void Thread::afficheGifsVentExterieur()
    35. {
    36. if (m_threadGainable.gifVentilationExtFr == true) {
    37. m_threadHysteresis.hysteresisTempVitesseExtFroid();
    38. if (m_threadHysteresis.tempVitExtFr == false) {
    39. emit afficheGifsVentExt(0);
    40. } else {
    41. emit afficheGifsVentExt(1);
    42. }
    43. } else {
    44. emit afficheGifsVentExt(2);
    45. }
    46. }
    47. void Thread::run()
    48. {
    49. while (1) {
    50.  
    51. QCoreApplication::processEvents();
    52.  
    53. m_threadSondes.lectureTemperatures();
    54. lectureSondes();
    55.  
    56. afficheLabelModes();
    57. afficheGifsNettoyageFiltre();
    58. afficheGifsVentInterieur();
    59. afficheGifsVentExterieur();
    60. afficheGifCompresseur();
    61.  
    62. if (departGainable == true) {
    63. m_threadGainable.gainable();
    64. } else {
    65. m_threadGainable.nettoyageFiltreArret();
    66. }
    67. }
    68. }
    To copy to clipboard, switch view to plain text mode 

    and it works well.


    Added after 1 20 minutes:


    Wouldn't it be better to create signals directly from "gainable.cpp" where I have the bool false/true

    because I execute it "fonction gainable()" on the thread ?????
    Last edited by ludoQtCreator; 3rd February 2025 at 18:59.

  17. #16
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,287
    Thanks
    310
    Thanked 868 Times in 855 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLabel QPixmap change

    Wouldn't it be better to create signals directly from "gainable.cpp" where I have the bool false/true
    You could do that, but you would have to derive your "gainable" class from QObject and add the "Q_OBJECT" macro.

    You would also have to somehow connect those signals to your MainWindow slots. That would be hard to do, since you cannot access the m_threadGainable member variable directly from MainWindow to set up the connect() statement. I think it would be better to use the code you have now.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  18. #17
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,539
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLabel QPixmap change

    Quote Originally Posted by ludoQtCreator View Post
    Qt Code:
    1. void Thread::run()
    2. {
    3. while(1) {
    4. if (departGainable == true) {
    5. affichageGifChauffe();
    6. ....
    7. } else {
    8. ....
    9. }
    10. QCoreApplication::processEvents(); // MUST do this otherwise your thread cannot process signals from MainWindow
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    By the way, using such a construction for the run() method is a very bad idea. The method does nothing and uses 100% of the processor. You should use a signal generated when the state of the tracked object changes or a timer that periodically starts the appropriate method.

  19. #18
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,287
    Thanks
    310
    Thanked 868 Times in 855 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLabel QPixmap change

    By the way, using such a construction for the run() method is a very bad idea.
    This is true. I was working on solving one problem at a time
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  20. #19
    Join Date
    Jan 2025
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLabel QPixmap change

    hi to you, so I finished putting all the gifs and my label with connect. and it works.

    Qt Code:
    1. void MainWindow::changeLabel(int m_mode)
    2. {
    3. switch (m_mode) {
    4.  
    5. case 0:
    6.  
    7. m_label ->setPixmap(QPixmap("/home/ludo/Qt/test2/build/images/froid.jpg"));
    8.  
    9. break;
    10.  
    11. case 1:
    12.  
    13. m_label ->setPixmap(QPixmap("/home/ludo/Qt/test2/build/images/chauffage.jpg"));
    14.  
    15. break;
    16.  
    17. case 2:
    18.  
    19. m_label ->setPixmap(QPixmap("/home/ludo/Qt/test2/build/images/canicule.jpg"));
    20.  
    21. break;
    22.  
    23. default:
    24.  
    25. m_label ->setPixmap(QPixmap("/home/ludo/Qt/test2/build/images/abigael.jpg"));
    26.  
    27. break;
    28.  
    29. }
    30. }
    31.  
    32. void MainWindow::affichageGifsNettoyageFiltre(int m_gifsFiltre)
    33. {
    34. switch (m_gifsFiltre) {
    35.  
    36. case 0:
    37.  
    38. m_labelGifArretProgramme ->show();
    39. m_labelGifNettoyageFiltre ->show();
    40.  
    41. break;
    42.  
    43. case 1:
    44.  
    45. m_labelGifArretProgramme ->hide();
    46. m_labelGifNettoyageFiltre ->hide();
    47. m_labelGifNettoyageEnCours ->show();
    48.  
    49. break;
    50.  
    51. case 2:
    52.  
    53. m_labelGifNettoyageFiltre ->show();
    54.  
    55. break;
    56.  
    57. case 3:
    58.  
    59. m_labelGifNettoyageEnCours ->hide();
    60.  
    61. break;
    62.  
    63. default:
    64.  
    65. m_labelGifNettoyageEnCours ->hide();
    66. m_labelGifArretProgramme ->hide();
    67. m_labelGifNettoyageFiltre ->hide();
    68.  
    69. break;
    70. }
    71. }
    72.  
    73. void MainWindow::affichageGifsVentInt(int m_gifsVentilationInt)
    74. {
    75. switch (m_gifsVentilationInt) {
    76.  
    77. case 0:
    78.  
    79. m_labelGifVentInt ->show();
    80. m_labelGifVitesse1Int ->hide();
    81. m_labelGifVitesse4Int ->show();
    82.  
    83. break;
    84.  
    85. case 1:
    86.  
    87. m_labelGifVentInt ->show();
    88. m_labelGifVitesse1Int ->show();
    89. m_labelGifVitesse4Int ->hide();
    90.  
    91. break;
    92.  
    93. default:
    94.  
    95. m_labelGifVentInt ->hide();
    96. m_labelGifVitesse1Int ->hide();
    97. m_labelGifVitesse4Int ->hide();
    98.  
    99. break;
    100. }
    101. }
    102. void MainWindow::affichageGifsVentExt(int m_gifsVentilationExt)
    103. {
    104. switch (m_gifsVentilationExt) {
    105.  
    106. case 0:
    107.  
    108. m_labelGifVentExt ->show();
    109. m_labelGifVitesse1Ext ->show();
    110. m_labelGifVitesse2Ext ->hide();
    111.  
    112. break;
    113.  
    114. case 1:
    115.  
    116. m_labelGifVentExt ->show();
    117. m_labelGifVitesse1Ext ->hide();
    118. m_labelGifVitesse2Ext ->show();
    119.  
    120. break;
    121.  
    122. default:
    123.  
    124. m_labelGifVentExt ->hide();
    125. m_labelGifVitesse1Ext ->hide();
    126. m_labelGifVitesse2Ext ->hide();
    127.  
    128. break;
    129. }
    130. }
    131.  
    132. void MainWindow::affichageGifComp(int m_gifCompresseur)
    133. {
    134. switch (m_gifCompresseur) {
    135.  
    136. case 0:
    137.  
    138. m_labelGifFroid ->show();
    139.  
    140. break;
    141.  
    142. case 1:
    143.  
    144. m_labelGifChauffage ->show();
    145.  
    146. break;
    147.  
    148. default:
    149.  
    150. m_labelGifFroid ->hide();
    151. m_labelGifChauffage ->hide();
    152.  
    153. break;
    154. }
    155.  
    156. }
    157.  
    158. void MainWindow::affichageGifDegivrage(int m_gifDegivrage)
    159. {
    160. switch (m_gifDegivrage) {
    161.  
    162. case 0:
    163.  
    164. m_labelGifDegivrage ->show();
    165.  
    166. break;
    167.  
    168. case 1:
    169.  
    170. m_labelGifDegivrage ->show();
    171. m_labelGifEclaire ->show();
    172.  
    173. default:
    174.  
    175. m_labelGifDegivrage ->hide();
    176. m_labelGifEclaire ->hide();
    177.  
    178. break;
    179. }
    180.  
    181. }
    182.  
    183. void MainWindow::affichageGifEgouttage(int m_gifEgouttage)
    184. {
    185. switch (m_gifEgouttage) {
    186.  
    187. case 0:
    188.  
    189. m_labelGifEgouttage ->show();
    190.  
    191. break;
    192.  
    193. default:
    194.  
    195. m_labelGifEgouttage ->hide();
    196.  
    197. break;
    198. }
    199. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. MainWindow::MainWindow(QWidget *parent)
    4. :QWidget (parent)
    5. {
    6. qDebug() << "mainwindow";
    7.  
    8. m_mainwindowThread.start();
    9.  
    10. m_window = new QWidget;
    11. m_window ->setFixedSize(1920,1080);
    12. m_window ->setWindowTitle("Gainable");
    13. adjustSize();
    14.  
    15. connect(&m_mainwindowThread, &Thread::majLabel, this, &MainWindow::changeLabel);
    16. m_label = new QLabel(m_window);
    17. changeLabel(3);
    18.  
    19. m_disp1 = new QGroupBox("Temp°C Ext",m_window);
    20. m_disp1 ->setStyleSheet("QGroupBox:title {color: orangered;}");
    21. m_disp1 ->setFont(QFont("Times", 18, QFont::Bold));
    22. m_disp1 ->setGeometry(200,40,240,120);
    23. m_mainwindowThread.m_tempExtLue = new QLCDNumber(m_disp1);
    24. m_mainwindowThread.m_tempExtLue ->setGeometry(0,35,240,80);
    25.  
    26. m_disp2 = new QGroupBox("Temp°C UnitExt",m_window);
    27. m_disp2 ->setStyleSheet("QGroupBox:title {color: orangered;}");
    28. m_disp2 ->setFont(QFont("Times", 18, QFont::Bold));
    29. m_disp2 ->setGeometry(520,40,240,120);
    30. m_mainwindowThread.m_tempUnitExtLue = new QLCDNumber(m_disp2);
    31. m_mainwindowThread.m_tempUnitExtLue ->setGeometry(0,35,240,80);
    32.  
    33. m_disp3 = new QGroupBox("Temp°C EcUnitExt",m_window);
    34. m_disp3 ->setStyleSheet("QGroupBox:title {color: orangered;}");
    35. m_disp3 ->setFont(QFont("Times", 18, QFont::Bold));
    36. m_disp3 ->setGeometry(840,40,240,120);
    37. m_mainwindowThread.m_tempEcExtLue = new QLCDNumber(m_disp3);
    38. m_mainwindowThread.m_tempEcExtLue ->setGeometry(0,35,240,80);
    39.  
    40. m_disp4 = new QGroupBox("Temp°C UnitInt",m_window);
    41. m_disp4 ->setStyleSheet("QGroupBox:title {color: orangered;}");
    42. m_disp4 ->setFont(QFont("Times", 18, QFont::Bold));
    43. m_disp4 ->setGeometry(1160,40,240,120);
    44. m_mainwindowThread.m_tempUnitIntLue = new QLCDNumber(m_disp4);
    45. m_mainwindowThread.m_tempUnitIntLue ->setGeometry(0,35,240,80);
    46.  
    47. m_disp5 = new QGroupBox("Temp°C EcUnitInt",m_window);
    48. m_disp5 ->setStyleSheet("QGroupBox:title {color: orangered;}");
    49. m_disp5 ->setFont(QFont("Times", 18, QFont::Bold));
    50. m_disp5 ->setGeometry(1480,40,240,120);
    51. m_mainwindowThread.m_tempEcIntLue = new QLCDNumber(m_disp5);
    52. m_mainwindowThread.m_tempEcIntLue ->setGeometry(0,35,240,80);
    53.  
    54. m_marche = new QPushButton("Démarrage ??",m_window);
    55. m_marche ->setGeometry(1080,900,240,95);
    56. m_marche ->setStyleSheet("font-size: 30px;background-color: lime");
    57. m_marche ->hide();
    58.  
    59. m_consigne = new QPushButton("Consignes",m_window);
    60. m_consigne ->setGeometry(1340,900,240,95);
    61. m_consigne ->setStyleSheet("font-size: 30px;");
    62. m_consigne ->show();
    63.  
    64. m_stop = new QPushButton("Stop ??",m_window);
    65. m_stop ->setGeometry(1600,900,240,95);
    66. m_stop ->setStyleSheet("font-size: 30px;background-color: red");
    67. m_stop ->show();
    68.  
    69. m_labelGifNettoyageEnCours = new QLabel(m_window);
    70. m_labelGifNettoyageEnCours ->setGeometry(720,300,480,480);
    71. m_movieGifNettoyageEnCours = new QMovie("/home/ludo/Qt/test2/build/gif/nettoyageEnCours.gif");
    72. m_labelGifNettoyageEnCours ->setMovie(m_movieGifNettoyageEnCours);
    73. m_movieGifNettoyageEnCours ->start();
    74. m_labelGifNettoyageFiltre = new QLabel(m_window);
    75. m_labelGifNettoyageFiltre ->setGeometry(20,840,200,200);
    76. m_movieGifNettoyageFiltre = new QMovie("/home/ludo/Qt/test2/build/gif/nettoyageFiltre.gif");
    77. m_labelGifNettoyageFiltre ->setMovie(m_movieGifNettoyageFiltre);
    78. m_movieGifNettoyageFiltre ->start();
    79. m_labelGifArretProgramme = new QLabel(m_window);
    80. m_labelGifArretProgramme ->setGeometry(720,300,480,480);
    81. m_movieGifArretProgramme = new QMovie("/home/ludo/Qt/test2/build/gif/arretProgrammeFiltre.gif");
    82. m_labelGifArretProgramme ->setMovie(m_movieGifArretProgramme);
    83. m_movieGifArretProgramme ->start();
    84.  
    85. m_labelGifVentInt = new QLabel(m_window);
    86. m_labelGifVentInt ->setGeometry(1105,845,200,200);
    87. m_movieGifVentInt = new QMovie("/home/ludo/Qt/test2/build/gif/ventilateurInt.gif");
    88. m_labelGifVentInt ->setMovie(m_movieGifVentInt);
    89. m_movieGifVentInt ->start();
    90. m_labelGifVitesse1Int = new QLabel(m_window);
    91. m_labelGifVitesse1Int ->setGeometry(1040,900,60,60);
    92. m_movieGifVitesse1Int = new QMovie("/home/ludo/Qt/test2/build/gif/vitesse1.gif");
    93. m_labelGifVitesse1Int ->setMovie(m_movieGifVitesse1Int);
    94. m_movieGifVitesse1Int ->start();
    95. m_labelGifVitesse4Int = new QLabel(m_window);
    96. m_labelGifVitesse4Int ->setGeometry(1040,900,60,60);
    97. m_movieGifVitesse4Int = new QMovie("/home/ludo/Qt/test2/build/gif/vitesse4.gif");
    98. m_labelGifVitesse4Int ->setMovie(m_movieGifVitesse4Int);
    99. m_movieGifVitesse4Int ->start();
    100.  
    101. m_labelGifVentExt = new QLabel(m_window);
    102. m_labelGifVentExt ->setGeometry(910,830,200,200);
    103. m_movieGifVentExt = new QMovie("/home/ludo/Qt/test2/build/gif/ventilateurExt.gif");
    104. m_labelGifVentExt ->setMovie(m_movieGifVentExt);
    105. m_movieGifVentExt ->start();
    106. m_labelGifVitesse1Ext = new QLabel(m_window);
    107. m_labelGifVitesse1Ext ->setGeometry(860,900,60,60);
    108. m_movieGifVitesse1Ext = new QMovie("/home/ludo/Qt/test2/build/gif/vitesse1.gif");
    109. m_labelGifVitesse1Ext ->setMovie(m_movieGifVitesse1Ext);
    110. m_movieGifVitesse1Ext ->start();
    111. m_labelGifVitesse2Ext = new QLabel(m_window);
    112. m_labelGifVitesse2Ext ->setGeometry(860,900,60,60);
    113. m_movieGifVitesse2Ext = new QMovie("/home/ludo/Qt/test2/build/gif/vitesse2.gif");
    114. m_labelGifVitesse2Ext ->setMovie(m_movieGifVitesse2Ext);
    115. m_movieGifVitesse2Ext ->start();
    116.  
    117. m_labelGifFroid = new QLabel(m_window);
    118. m_labelGifFroid ->setGeometry(1210,845,200,200);
    119. m_movieGifFroid = new QMovie("/home/ludo/Qt/test2/build/gif/froid.gif");
    120. m_labelGifFroid ->setMovie(m_movieGifFroid);
    121. m_movieGifFroid ->start();
    122.  
    123. m_labelGifChauffage = new QLabel(m_window);
    124. m_labelGifChauffage ->setGeometry(1220,840,200,200);
    125. m_movieGifChauffage = new QMovie("/home/ludo/Qt/test2/build/gif/chauffage.gif");
    126. m_labelGifChauffage ->setMovie(m_movieGifChauffage);
    127. m_movieGifChauffage ->start();
    128.  
    129. m_labelGifDegivrage = new QLabel(m_window);
    130. m_labelGifDegivrage ->setGeometry(1220,850,200,200);
    131. m_movieGifDegivrage = new QMovie("/home/ludo/Qt/test2/build/gif/degivrage.gif");
    132. m_labelGifDegivrage ->setMovie(m_movieGifDegivrage);
    133. m_movieGifDegivrage ->start();
    134.  
    135. m_labelGifEclaire = new QLabel(m_window);
    136. m_labelGifEclaire ->setGeometry(1160,830,200,200);
    137. m_movieGifEclaire = new QMovie("/home/ludo/Qt/test2/build/gif/eclaire.gif");
    138. m_labelGifEclaire ->setMovie(m_movieGifEclaire);
    139. m_movieGifEclaire ->start();
    140.  
    141. m_labelGifEgouttage = new QLabel(m_window);
    142. m_labelGifEgouttage ->setGeometry(1120,820,200,200);
    143. m_movieGifEgouttage = new QMovie("/home/ludo/Qt/test2/build/gif/egouttage.gif");
    144. m_labelGifEgouttage ->setMovie(m_movieGifEgouttage);
    145. m_movieGifEgouttage ->start();
    146.  
    147. connect(&m_mainwindowThread, &Thread::afficheGifsFiltre, this, &MainWindow::affichageGifsNettoyageFiltre);
    148. affichageGifsNettoyageFiltre(4);
    149.  
    150. connect(&m_mainwindowThread, &Thread::afficheGifsVentInt, this, &MainWindow::affichageGifsVentInt);
    151. affichageGifsVentInt(2);
    152. connect(&m_mainwindowThread, &Thread::afficheGifsVentExt, this, &MainWindow::affichageGifsVentExt);
    153. affichageGifsVentExt(2);
    154.  
    155. connect(&m_mainwindowThread, &Thread::afficheGifComp, this, &MainWindow::affichageGifComp);
    156. affichageGifComp(2);
    157.  
    158. connect(&m_mainwindowThread, &Thread::afficheGifDeg, this, &MainWindow::affichageGifDegivrage);
    159. affichageGifDegivrage(2);
    160. connect(&m_mainwindowThread, &Thread::afficheGifEgout, this, &MainWindow::affichageGifEgouttage);
    161. affichageGifEgouttage(1);
    162.  
    163.  
    164. connect(this, &MainWindow::changeGainableState, &m_mainwindowThread, &Thread::onChangeGainableState);
    165.  
    166. connect(m_marche, &QPushButton::clicked, this, &MainWindow::reStartGainable);
    167. connect(m_consigne, &QPushButton::clicked, this, &MainWindow::afficheConsignes);
    168. connect(m_stop, &QPushButton::clicked, this, &MainWindow::stopGainable);
    169.  
    170. m_window->show();
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef THREAD_H
    2. #define THREAD_H
    3. #include <QtWidgets>
    4. #include <QThread>
    5.  
    6. #include "sondes.h"
    7. #include "parametres.h"
    8. #include "gainable.h"
    9. #include "hysteresisvitesses.h"
    10.  
    11. class Thread: public QThread
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. Thread();
    17.  
    18. QLCDNumber *m_tempExtLue;
    19. QLCDNumber *m_tempUnitExtLue;
    20. QLCDNumber *m_tempEcExtLue;
    21. QLCDNumber *m_tempUnitIntLue;
    22. QLCDNumber *m_tempEcIntLue;
    23.  
    24. bool departGainable = true;
    25.  
    26. void lectureSondes();
    27.  
    28. void afficheLabelModes();
    29.  
    30. void afficheGifsNettoyageFiltre();
    31.  
    32. void afficheGifsVentInterieur();
    33. void afficheGifsVentExterieur();
    34.  
    35. void afficheGifCompresseur();
    36.  
    37. void afficheGifDegivrage();
    38. void afficheGifEgouttage();
    39.  
    40. public slots:
    41. void onChangeGainableState(bool m_state);
    42.  
    43. signals:
    44. void majLabel(int m_mode);
    45.  
    46. void afficheGifsFiltre(int m_gifsFiltre);
    47.  
    48. void afficheGifsVentInt(int m_gifsVentilationInt);
    49. void afficheGifsVentExt(int m_gifsVentilationExt);
    50.  
    51. void afficheGifComp(int m_gifCompresseur);
    52.  
    53. void afficheGifDeg(int m_gifDegivrage);
    54. void afficheGifEgout(int m_gifEgouttage);
    55.  
    56.  
    57.  
    58. private:
    59. Sondes m_threadSondes;
    60.  
    61. Gainable m_threadGainable;
    62.  
    63. HysteresisVitesses m_threadHysteresis;
    64.  
    65. Parametres *m_threadParametres;
    66.  
    67. void run();
    68. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "thread.h"
    2.  
    3. Thread::Thread()
    4. {
    5. qDebug() << "Thread";
    6.  
    7. m_threadParametres = new Parametres(QString("settings/parametres.ini"), QSettings::IniFormat);
    8. }
    9.  
    10. void Thread::lectureSondes()
    11. {
    12. m_threadParametres ->lireTemperatures();
    13.  
    14. m_tempExtLue ->display(m_threadParametres ->temperatureExt);
    15. m_tempUnitExtLue ->display(m_threadParametres ->temperatureUnitExt);
    16. m_tempEcExtLue ->display(m_threadParametres ->temperatureEcExt);
    17. m_tempUnitIntLue ->display(m_threadParametres ->temperatureUnitInt);
    18. m_tempEcIntLue ->display(m_threadParametres ->temperatureEcInt);
    19. }
    20.  
    21. void Thread::afficheLabelModes()
    22. {
    23. if (m_threadGainable.labelModeFroid == true) {
    24. emit majLabel(0);
    25. } else if (m_threadGainable.labelModeChauffage == true) {
    26. emit majLabel(1);
    27. } else if (m_threadGainable.labelModeCanicule == true) {
    28. emit majLabel(2);
    29. } else {
    30. emit majLabel(3);
    31. }
    32. }
    33.  
    34. void Thread::onChangeGainableState(bool m_state)
    35. {
    36. departGainable = m_state;
    37. }
    38.  
    39. void Thread::afficheGifsNettoyageFiltre()
    40. {
    41. if (m_threadGainable.gifArretProgrammeFiltre == true) {
    42. emit afficheGifsFiltre(0);
    43. } else if (m_threadGainable.gifNettoyageFiltreEnCours == true) {
    44. emit afficheGifsFiltre(1);
    45. } else {
    46. if (m_threadGainable.gifNettoyageFiltre == true) {
    47. emit afficheGifsFiltre(2);
    48. } else {
    49. emit afficheGifsFiltre(3);
    50. }
    51. }
    52. }
    53.  
    54. void Thread::afficheGifsVentInterieur()
    55. {
    56. if (m_threadGainable.gifVentilation == true) {
    57. emit afficheGifsVentInt(0);// affiche grande vitesse
    58. } else {
    59. if (m_threadGainable.gifVentilationIntFr == true) {
    60. m_threadHysteresis.hysteresisTempVitesseIntFroid();
    61. if (m_threadHysteresis.tempVitIntFr == false) {
    62. emit afficheGifsVentInt(1); // petite vitesse si faux
    63. }else {
    64. emit afficheGifsVentInt(0);
    65. }
    66. } else if (m_threadGainable.gifVentilationIntCh == true) {
    67. m_threadHysteresis.hysteresisTempVitesseIntChauf();
    68. if (m_threadHysteresis.tempVitIntCh == true) {
    69. emit afficheGifsVentInt(1);
    70. } else {
    71. emit afficheGifsVentInt(0);
    72. }
    73. } else if(m_threadGainable.gifVentilationDegFr == true) {
    74. emit afficheGifsVentInt(0);
    75. } else {
    76. emit afficheGifsVentInt(2);// efface gif ventillation interieur
    77. }
    78. }
    79. }
    80.  
    81. void Thread::afficheGifsVentExterieur()
    82. {
    83. if (m_threadGainable.gifVentilationExtFr == true) {
    84. m_threadHysteresis.hysteresisTempVitesseExtFroid();
    85. if (m_threadHysteresis.tempVitExtFr == false) {
    86. emit afficheGifsVentExt(0);
    87. } else {
    88. emit afficheGifsVentExt(1);
    89. }
    90. } else if (m_threadGainable.gifVentilationExtCh == true) {
    91. m_threadHysteresis.hysteresisTempVitesseExtChauf();
    92. if (m_threadHysteresis.tempVitExtCh == true) {
    93. emit afficheGifsVentExt(0);
    94. } else {
    95. emit afficheGifsVentExt(1);
    96. }
    97. } else {
    98. emit afficheGifsVentExt(2);
    99. }
    100. }
    101.  
    102. void Thread::afficheGifCompresseur()
    103. {
    104. if (m_threadGainable.gifFroid == true) {
    105. emit afficheGifComp(0);
    106. } else if (m_threadGainable.gifChauffage == true) {
    107. emit afficheGifComp(1);
    108. } else {
    109. emit afficheGifComp(2);
    110. }
    111. }
    112.  
    113. void Thread::afficheGifDegivrage()
    114. {
    115. if (m_threadGainable.gifDegivrage == true) {
    116. if (m_threadGainable.gifElectrique == true) {
    117. emit afficheGifDeg(1);
    118. } else {
    119. emit afficheGifDeg(0);
    120. }
    121. } else {
    122. emit afficheGifDeg(2);
    123. }
    124. }
    125.  
    126. void Thread::afficheGifEgouttage()
    127. {
    128. if (m_threadGainable.gifEgouttage == true) {
    129. emit afficheGifEgout(0);
    130. } else {
    131. emit afficheGifEgout(1);
    132. }
    133. }
    134.  
    135. void Thread::run()
    136. {
    137. while (1) {
    138.  
    139. m_threadSondes.lectureTemperatures();
    140. lectureSondes();
    141.  
    142. afficheLabelModes();
    143. afficheGifsNettoyageFiltre();
    144. afficheGifsVentInterieur();
    145. afficheGifsVentExterieur();
    146. afficheGifCompresseur();
    147. afficheGifDegivrage();
    148. afficheGifEgouttage();
    149.  
    150. if (departGainable == true) {
    151. m_threadGainable.gainable();
    152. } else {
    153. m_threadGainable.nettoyageFiltreArret();
    154. }
    155. QCoreApplication::processEvents();
    156. }
    157. }
    To copy to clipboard, switch view to plain text mode 


    Added after 5 minutes:


    if you see things to modify!!

    Afterwards I'm going to open another post for how to read my probes because I'm having a problem with the temperatures! it goes from 10° to 0°, whereas before it worked: 10° to 9° to 8°...


    Added after 9 minutes:


    actually I run A38% in processor on my ./test and 89% on the whole
    Last edited by ludoQtCreator; 5th February 2025 at 18:43.

  21. #20
    Join Date
    Jan 2025
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QLabel QPixmap change

    I noticed that my gifs move in slow motion except during the reading of my probes

Similar Threads

  1. QLabel does not repaint QPixmap
    By __Emanuel in forum Newbie
    Replies: 7
    Last Post: 11th February 2017, 16:18
  2. Replies: 3
    Last Post: 10th April 2011, 16:55
  3. DrawLine over QPixmap within Qlabel
    By Qt Coder in forum Qt Programming
    Replies: 8
    Last Post: 26th March 2009, 13:21
  4. Replies: 2
    Last Post: 20th January 2009, 08:13
  5. Replies: 1
    Last Post: 2nd August 2008, 16:46

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.