Results 1 to 20 of 21

Thread: Howto display QPixmap and Text?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2009
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Howto display QPixmap and Text?

    Thank you very much.
    I get it working. But why the read method is called so much times?
    I add a debug message to your MemFileHandler::read method and get the following output:
    Qt Code:
    1. Starting /home/segi/tmp/memfilehandler/memfilehandler...
    2. read: return 2844 counter 0
    3. read: return 2844 counter 1
    4. read: return 2844 counter 2
    5. ...
    6. read: return 2844 counter 27
    To copy to clipboard, switch view to plain text mode 
    Can I avoid these additional calls?
    Sadly there are a lot of errors at runtime:
    I tried big images: e.g. /usr/share/wallpapers/default-1600x1200.png
    Qt Code:
    1. Starting /home/segi/tmp/memfilehandler/memfilehandler...
    2. read: return 16384 counter 0
    3. read: return 16384 counter 1
    4. read: return 16384 counter 2
    5. ...
    6. read: return 16384 counter 27
    7. read: return 53 counter 28
    8. read: return 16384 counter 29
    9. libpng error: IDAT: CRC error
    To copy to clipboard, switch view to plain text mode 
    What can I do to avoid this error?
    On jpeg files I get:
    Qt Code:
    1. Starting /home/segi/tmp/memfilehandler/memfilehandler...
    2. read: return 378 counter 0
    3. read: return 378 counter 1
    4. Not a JPEG file: starts with 0xff 0xd9
    To copy to clipboard, switch view to plain text mode 
    I created a new jpg with gimp (100x100px only a white background).
    qDebug() << QImageReader::supportedImageFormats():
    Qt Code:
    1. Starting /home/sebastian/tmp/memfilehandler/memfilehandler...
    2. ("BW", "EPS", "EPSF", "EPSI", "EXR", "PCX", "PSD", "RGB", "RGBA", "SGI", "TGA", "XCF",
    3. "bmp", "bw", "dds", "eps", "epsf", "epsi", "exr", "gif", "ico", "jp2", "jpeg", "jpg",
    4. "mng", "pbm", "pcx", "pgm", "png", "ppm", "psd", "rgb", "rgba", "sgi", "svg",
    5. "tga", "tif", "tiff", "xbm", "xcf", "xpm", "xv")
    To copy to clipboard, switch view to plain text mode 
    What's the problem?

    Bye

  2. #2
    Join Date
    Jul 2009
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Howto display QPixmap and Text?

    Quote Originally Posted by segi View Post
    T
    I tried big images: e.g. /usr/share/wallpapers/default-1600x1200.png
    Qt Code:
    1. ...
    2. libpng error: IDAT: CRC error
    To copy to clipboard, switch view to plain text mode 
    What can I do to avoid this error?
    Sorry, my fault. I just copied and modified your MemFileHandler::read() method.
    I add
    Qt Code:
    1. m_pos+=maxlen
    To copy to clipboard, switch view to plain text mode 
    and the error on big files is gone.
    But why is this method called so often?
    Why doesn't work jpg files?

    Bye

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Howto display QPixmap and Text?

    What does QImageReader::supportedImageFormats() have to do with this?

    About the handler - it's probably buggy (although I can't see the bug) or incomplete. You'd have to reimplement every method from the interface and see which methods get called.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Jul 2009
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Howto display QPixmap and Text?

    Quote Originally Posted by wysota View Post
    What does QImageReader::supportedImageFormats() have to do with this?
    I thought the jpeg error would reasoned by a missing library or something like that.

    Bye

  5. #5
    Join Date
    Jul 2009
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Howto display QPixmap and Text?

    I now reimplement QAbstractFileEngine::isSequential() because it's called very often in the following methods:
    Qt Code:
    1. ICOReader::canRead(QIODevice *iodev)
    2. static QImageIOHandler *createReadHandlerHelper(QIODevice *device, const QByteArray &format, bool autoDetectImageFormat)
    3. somewhere in /usr/lib/kde4/plugins/imageformats/kimg_eps.so
    To copy to clipboard, switch view to plain text mode 
    If QAbstractFileEngine::isSequential() returns false QAbstractFileEngine::seek() is calling and the file will read once again. My isSequential() returns always true. (Now isSequential() is calling over 30 times but IHMO it's ok.)

    wysota: Thank you for your efforts.

    I try to solve the JPEG problem in another thread.

    Bye

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Howto display QPixmap and Text?

    But the device is not sequential...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jul 2009
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Howto display QPixmap and Text?

    Mh, I thought sequential means: "ABCDEFGH" and reading follows in the same order.
    I read the data from the sql table into a QByteArray. Isn't a QByteArray sequential in RAM?
    (I'm not a professional programmer. I don't really know how a QByteArray is stored in RAM.)
    This little change solves all my problems:
    Big files could be read in and jpg files are also read correctly.
    But I want to do it in the right way.
    I can't find another possibility to stop countless recalls of QAbstractFileEngine::read.
    Maybe QAbstractFileEngine::seek would be right. But I don't know what to change.

    Bye

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Howto display QPixmap and Text?

    Quote Originally Posted by segi View Post
    Mh, I thought sequential means: "ABCDEFGH" and reading follows in the same order.
    Sequential means you don't know how much data is available in the device and that you can only go "forward" with processing the data and never look back. In other words a sequential device is a device where implementing size() and seek() is not possible.


    I read the data from the sql table into a QByteArray. Isn't a QByteArray sequential in RAM?
    An opposite to sequential is "random access". QByteArray is a random-access (index based) container.

    I can't find another possibility to stop countless recalls of QAbstractFileEngine::read.
    Maybe QAbstractFileEngine::seek would be right. But I don't know what to change.
    My implementation of seek() is correct, the problem is elsewhere.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Howto display QPixmap and Text?

    Here is a corrected implementation - I wasn't updating position after a read attempt.
    Attached Files Attached Files
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. The following user says thank you to wysota for this useful post:

    segi (27th July 2009)

  11. #10
    Join Date
    Jul 2009
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Howto display QPixmap and Text?

    Thank you very much. It works like expected. (and isSequential() returns false now)
    The main problem was that i have testing with your little application and don't update the file position, too. I already noticed this a few posts above and changed it only in my app. Sorry for any inconvenience.
    A last little question....
    The application output:
    Qt Code:
    1. /home/segi/tmp/IMG_9066.JPG
    2. Open ok
    3. RAW: 2188490
    4. File read
    5. virtual qint64 MemFileHandler::read(char*, qint64) 0 2188490
    6. READ: 2188490
    7. MEM: 2188490
    8. virtual qint64 MemFileHandler::read(char*, qint64) 0 16384
    9. READ: 16384
    10. virtual bool MemFileHandler::seek(qint64) 0
    11. virtual qint64 MemFileHandler::read(char*, qint64) 0 16384
    12. READ: 16384
    13. virtual bool MemFileHandler::seek(qint64) 0
    14. virtual bool MemFileHandler::seek(qint64) 16384
    15. virtual qint64 MemFileHandler::read(char*, qint64) 16384
    16. READ: 16384
    17. virtual qint64 MemFileHandler::read(char*, qint64) 32768 16384
    18. READ: 16384
    19. virtual qint64 MemFileHandler::read(char*, qint64) 49152 16384
    To copy to clipboard, switch view to plain text mode 
    Why does Qt call this methods a few times before reading the real data?
    Qt Code:
    1. virtual bool MemFileHandler::seek(qint64) 0
    2. virtual qint64 MemFileHandler::read(char*, qint64) 0 16384
    To copy to clipboard, switch view to plain text mode 
    Is it possible that the QImageIOHandler wants to find out which image format the file is of?

    Bye

  12. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Howto display QPixmap and Text?

    Yes, that's possible. But that's just a guess. Is it important for you in any way? You can probably force the device to be sequential to omit that, if you want. But I wouldn't do that.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #12
    Join Date
    Jul 2009
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Howto display QPixmap and Text?

    It's not important for my app. I don't want to change this behaviour.
    I only want to know what happens.

Similar Threads

  1. QPixmap display on QGraphicsScene
    By febil in forum Qt Programming
    Replies: 2
    Last Post: 26th February 2009, 10:27
  2. Need Graphical Text on QPushButton/QLabel
    By JimDaniel in forum Qt Programming
    Replies: 6
    Last Post: 9th June 2008, 09:12
  3. Text on QPixmap
    By Fabix in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2006, 15:26

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
  •  
Qt is a trademark of The Qt Company.