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. Problem using setPixmap on a label

Problem using setPixmap on a label

Scheduled Pinned Locked Moved Solved Mobile and Embedded
7 Posts 2 Posters 1.7k Views
  • 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.
  • C Offline
    C Offline
    ciclonite
    wrote on last edited by
    #1

    Hi all,
    sorry for disturb.. I' m a very newbie with Qt and the C++ isn't my primary programming language..
    I've a problem when i try to change the pixmap from a slot function:
    Here the code :

    Nopaste

    Thanks a lot,
    Giovanni

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Look your constructor again: you have shadowed your class member variable with local version. So when you call e.g. on_ResistenzeOn_clicked you are setting an uninitialized pixmap on your label.

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

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ciclonite
        wrote on last edited by
        #3

        Hi,
        Thanks for reply, i've looked my constructor but i cannot find the problem.. Sorry! Where have i shadowed my class member with local version? In the constructor i've initialized the QPixmap with relative image.
        Thanks for patience.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by SGaist
          #4

          From your constructor with comments:

          ui->setupUi(this);
          QPixmap fire(":/images/Fire.png");
          QPixmap fireScaled = fire.scaled(QSize(131,121),Qt::KeepAspectRatio); // << Shadowing your class member fireScaled
          QPixmap cold(":/images/cold.png");
          QPixmap coldScaled = cold.scaled(QSize(131,121),Qt::KeepAspectRatio); // << Shadowing your class member coldeScaled
          

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

          1 Reply Last reply
          0
          • C Offline
            C Offline
            ciclonite
            wrote on last edited by
            #5

            SGaist : Sorry i'm a noob...
            Only the last question. I've solved the problem but i wish to know if this is trash code:
            On mainwindow.h i've declared :
            QPixmap *fire;
            QPixmap fireScaled;
            QPixmap *cold;
            QPixmap coldScaled;

            On mainwindow.c :
            ui->setupUi(this);
            fire = new QPixmap(":/images/Fire.png");
            fireScaled = fire->scaled(QSize(131,121),Qt::KeepAspectRatio);
            cold = new QPixmap(":/images/cold.png");
            coldScaled = cold->scaled(QSize(131,99),Qt::KeepAspectRatio);
            QPixmap tempDown(":/images/tempdown.png");

            Many thanks for your help and your patience.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              First thing: you almost never need to allocated a QPixmap (or QImage for that matter) on the heap.
              Second thing: since you only use fire and cold in the constructor it doesn't make sense to keep them.
              Last thing: don't forget to handle properly the deletion of stuff you allocate on the heap.

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

              1 Reply Last reply
              0
              • C Offline
                C Offline
                ciclonite
                wrote on last edited by
                #7

                Thanks a lot SGaist, problem solved!! :)

                1 Reply Last reply
                0

                • Login

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