Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. class derivated from QImage
Qt 6.11 is out! See what's new in the release blog

class derivated from QImage

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 931 Views 1 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
    stephane78 0
    wrote on last edited by
    #1

    Hi, I have problems with my class derivated from QImage for the copy and/or affectation (Ihave defined a copy constructor and an = operator). the copy and affectation don't work.
    shouldn't we derive from QImage and use a class containing a QImage instead ?

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

      No, call the base class operator= method.

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

      S 3 Replies Last reply
      1
      • gde23G Offline
        gde23G Offline
        gde23
        wrote on last edited by
        #2

        without any code for your class and the copyconstructor it is hard to tell where the bug is.

        1 Reply Last reply
        1
        • S Offline
          S Offline
          stephane78 0
          wrote on last edited by
          #3
          #ifndef IMAGE_H
          #define IMAGE_H
          
          #include <QImage>
          #include <QString>
          
          class Image : public QImage
          {
            bool used;
            QString filename;
            public:
            Image():QImage(),used(false){};
            Image(const QSize &size, Format format):QImage(size,format),used(false){};
            Image(const Image & i){used=i.used;filename=i.filename;};
            Image(const QImage &i ){used=false;filename=QString("");};
            Image & operator=(const Image & i);
            Image & operator=(const QImage &i);
            ~Image(){};
            Image scaled(const QSize);
            void setused(bool usd) {used=usd;};
            bool isused(){return used;};
            void setfilename(QString & s){filename=s;};
            QString & getfilename(){return filename;};
          
          };
          
          Q_DECLARE_METATYPE(Image)
          Q_DECLARE_OPAQUE_POINTER(Image *)
          
          #endif // IMAGE_H
          
          

          #include "image.h"

          Image & Image::operator=(const Image & i)
          {
          if(this!=&i)
          {

             used=i.used;filename=i.filename;
          

          }
          return *this;
          }
          Image & Image::operator=(const QImage & i)
          {
          if(this!=&i)
          {

             used=false;filename=QString("");
          

          }
          return *this;
          }
          Image Image::scaled(const QSize sz)
          {

          QImage res2=((QImage*)this)->scaled(sz);
          Image res=res2;
          return (res);
          

          }

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stephane78 0
            wrote on last edited by
            #4

            But I can test with a class containing a QImage(instead of derivating) and my two other variables to see if the bug comes from QImage

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

              Hi,

              You might want to call the base class operator, currently you are only assigning your custom fields.

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

              S 1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                You might want to call the base class operator, currently you are only assigning your custom fields.

                S Offline
                S Offline
                stephane78 0
                wrote on last edited by
                #6

                @SGaist thank you.
                do you mean like this ? :

                (QImage) (*this)=(QImage)i;
                

                in the = operator and in the copy constructor ?

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

                  No, call the base class operator= method.

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

                  S 3 Replies Last reply
                  1
                  • SGaistS SGaist

                    No, call the base class operator= method.

                    S Offline
                    S Offline
                    stephane78 0
                    wrote on last edited by
                    #8

                    @SGaist said in class derivated from QImage:

                    No, call the base class operator= method.

                    Thank you I have done :

                    QImage::operator=(i);
                    

                    and for the copy constructor ? should I do something else?

                    1 Reply Last reply
                    0
                    • SGaistS SGaist

                      No, call the base class operator= method.

                      S Offline
                      S Offline
                      stephane78 0
                      wrote on last edited by
                      #9

                      @SGaist thank you ok it is solved.

                      1 Reply Last reply
                      0
                      • SGaistS SGaist

                        No, call the base class operator= method.

                        S Offline
                        S Offline
                        stephane78 0
                        wrote on last edited by
                        #10

                        @SGaist I have another question:
                        How to send an Image * as parameter of a signal ?

                        I have put:

                        Q_DECLARE_METATYPE(Image)
                        Q_DECLARE_OPAQUE_POINTER(Image *) 
                        ```in the header
                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #11

                          Good !

                          Then please mark the thread as solved using the "Topic Tools" or use the three doted menu beside the answer that you deem correct so that other forum users may know a solution has been found.

                          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

                          • Login

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