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. Bug in QImage
Forum Updated to NodeBB v4.3 + New Features

Bug in QImage

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 719 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.
  • W Offline
    W Offline
    wostka
    wrote on last edited by
    #1

    When I build an run this snippet on MinGW it works, on MSCV it doesn't. Both with newest Qt6.5.2 updates. It's a known bug? I can't find anything on Internet?

    extern BaseModel basemodel;
    [...]
    void BoardView::paintPieces(QPainter *p) {
    auto w = p->window().width();  //p->viewport().width();
    auto h = p->window().height(); //p->viewport().height();    
    p->drawPixmap(
                      QRect(50, 50, w, h), 
                      QPixmap::fromImage(basemodel.board.pieces[0][0].img));
    }
    ________________________
    [console output on MinGW]
    QImage(QSize(102, 102),format=QImage::Format_ARGB32,depth=32,devicePixelRatio=1,bytesPerLine=408,sizeInBytes=41616)
    
    [console output on MSCV 2019]
    QImage(null)
    

    Best regards

    jsulmJ 1 Reply Last reply
    0
    • jsulmJ jsulm

      @wostka said in Bug in QImage:

      In the ctor of board from a struct named Piece

      Why don't you show the code?

      W Offline
      W Offline
      wostka
      wrote on last edited by
      #9

      One workaround: Have to add

      Q_INIT_RESOURCE(res); //res = the .qrc file, e.g. res.qrc
      

      then it run under MSVC. Not a bug, a feature... :D

      see https://doc.qt.io/qt-6/resources.html#explicit-loading-and-unloading-of-embedded-resources

      Thanks to @jsulm and @Chris-Kawa

      Christian EhrlicherC 1 Reply Last reply
      0
      • W wostka

        When I build an run this snippet on MinGW it works, on MSCV it doesn't. Both with newest Qt6.5.2 updates. It's a known bug? I can't find anything on Internet?

        extern BaseModel basemodel;
        [...]
        void BoardView::paintPieces(QPainter *p) {
        auto w = p->window().width();  //p->viewport().width();
        auto h = p->window().height(); //p->viewport().height();    
        p->drawPixmap(
                          QRect(50, 50, w, h), 
                          QPixmap::fromImage(basemodel.board.pieces[0][0].img));
        }
        ________________________
        [console output on MinGW]
        QImage(QSize(102, 102),format=QImage::Format_ARGB32,depth=32,devicePixelRatio=1,bytesPerLine=408,sizeInBytes=41616)
        
        [console output on MSCV 2019]
        QImage(null)
        

        Best regards

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @wostka Where do you output anything on console?
        To me it is not clear what exactly does not work.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        W 1 Reply Last reply
        1
        • jsulmJ jsulm

          @wostka Where do you output anything on console?
          To me it is not clear what exactly does not work.

          W Offline
          W Offline
          wostka
          wrote on last edited by
          #3

          @jsulm I have adapt the code.
          The original code is a loop which iterates a 2-dim Array (pieces) which has stored e.g. an QImage (img)...This Array is stored in a class called board and this is stored in a class called basemodel. basemodel ist global.
          The methode paintPieces is called in the paintEvent methode of a view which paints the board of a game. The methode paintPieces paints the pieces of the board.
          The console output comes from

          p->drawPixmap(...
          qDebug() << basemodel.board.pieces[0][0].img;
          

          The problem is, that the same code generated by different compilers one times works, and at the other time not and I dont know why.
          Hope its clearer now whats the situation.

          jsulmJ 1 Reply Last reply
          0
          • W wostka

            @jsulm I have adapt the code.
            The original code is a loop which iterates a 2-dim Array (pieces) which has stored e.g. an QImage (img)...This Array is stored in a class called board and this is stored in a class called basemodel. basemodel ist global.
            The methode paintPieces is called in the paintEvent methode of a view which paints the board of a game. The methode paintPieces paints the pieces of the board.
            The console output comes from

            p->drawPixmap(...
            qDebug() << basemodel.board.pieces[0][0].img;
            

            The problem is, that the same code generated by different compilers one times works, and at the other time not and I dont know why.
            Hope its clearer now whats the situation.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @wostka said in Bug in QImage:

            img

            How are these QImage instances created?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #5

              If those are images read from files or resources you're most likely just missing the plugin for that format in your deployment directory.

              W 1 Reply Last reply
              0
              • Chris KawaC Chris Kawa

                If those are images read from files or resources you're most likely just missing the plugin for that format in your deployment directory.

                W Offline
                W Offline
                wostka
                wrote on last edited by
                #6

                @jsulm In the ctor of board from a struct named Piece
                @Chris-Kawa The plugins seems to be on the right place. The problem arise too, if I "deploy" the exe with windeployqt. The

                qDebug() << QImageReader::supportedImageFormats();
                

                gives in both cases ".png", whats right.

                Perhaps some pics:
                This with MinGW-Kit
                Screenshot 2023-08-17 224005.jpg
                This with MSVC
                Screenshot 2023-08-17 224143.jpg

                If I change the Kit from MinGW to MSVC.
                Screenshot 2023-08-17 224349.jpg

                Chris KawaC jsulmJ 2 Replies Last reply
                0
                • W wostka

                  @jsulm In the ctor of board from a struct named Piece
                  @Chris-Kawa The plugins seems to be on the right place. The problem arise too, if I "deploy" the exe with windeployqt. The

                  qDebug() << QImageReader::supportedImageFormats();
                  

                  gives in both cases ".png", whats right.

                  Perhaps some pics:
                  This with MinGW-Kit
                  Screenshot 2023-08-17 224005.jpg
                  This with MSVC
                  Screenshot 2023-08-17 224143.jpg

                  If I change the Kit from MinGW to MSVC.
                  Screenshot 2023-08-17 224349.jpg

                  Chris KawaC Offline
                  Chris KawaC Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  @wostka Before you jump to conclusions do a basic test:

                  int main(int argc, char *argv[])
                  {
                      QApplication a(argc, argv);
                      qDebug() << QImage("C:/Explicit/path/to/some/file.png");
                  }
                  

                  Does that work?

                  1 Reply Last reply
                  1
                  • W wostka

                    @jsulm In the ctor of board from a struct named Piece
                    @Chris-Kawa The plugins seems to be on the right place. The problem arise too, if I "deploy" the exe with windeployqt. The

                    qDebug() << QImageReader::supportedImageFormats();
                    

                    gives in both cases ".png", whats right.

                    Perhaps some pics:
                    This with MinGW-Kit
                    Screenshot 2023-08-17 224005.jpg
                    This with MSVC
                    Screenshot 2023-08-17 224143.jpg

                    If I change the Kit from MinGW to MSVC.
                    Screenshot 2023-08-17 224349.jpg

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @wostka said in Bug in QImage:

                    In the ctor of board from a struct named Piece

                    Why don't you show the code?

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    W 1 Reply Last reply
                    1
                    • jsulmJ jsulm

                      @wostka said in Bug in QImage:

                      In the ctor of board from a struct named Piece

                      Why don't you show the code?

                      W Offline
                      W Offline
                      wostka
                      wrote on last edited by
                      #9

                      One workaround: Have to add

                      Q_INIT_RESOURCE(res); //res = the .qrc file, e.g. res.qrc
                      

                      then it run under MSVC. Not a bug, a feature... :D

                      see https://doc.qt.io/qt-6/resources.html#explicit-loading-and-unloading-of-embedded-resources

                      Thanks to @jsulm and @Chris-Kawa

                      Christian EhrlicherC 1 Reply Last reply
                      0
                      • W wostka has marked this topic as solved on
                      • W wostka

                        One workaround: Have to add

                        Q_INIT_RESOURCE(res); //res = the .qrc file, e.g. res.qrc
                        

                        then it run under MSVC. Not a bug, a feature... :D

                        see https://doc.qt.io/qt-6/resources.html#explicit-loading-and-unloading-of-embedded-resources

                        Thanks to @jsulm and @Chris-Kawa

                        Christian EhrlicherC Online
                        Christian EhrlicherC Online
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #10

                        @wostka said in Bug in QImage:

                        Not a bug, a feature... :D

                        No feature but a mandatory thing - otherwise there is no reference to the resource and the lnker can throw it away.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        1

                        • Login

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