Results 1 to 11 of 11

Thread: [Qt 4.6.3] : pixmap resource for a label

  1. #1
    Join Date
    Sep 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default [Qt 4.6.3] : pixmap resource for a label

    Hello everyone,


    I wanted to associate a pixmap to a QLabel.
    For that, I trusted Qt Designer.
    I declared my pixmap to a qt resource file
    and then have associated with my famous QLabel.

    uic generates the following line:


    Qt Code:
    1. stateIndicator-> setPixmap (QPixmap (QString:: fromUtf8 (":/icons/amber-on.ico")));
    To copy to clipboard, switch view to plain text mode 

    To me, it seems correct.

    The compilation of the application goes smoothly.
    Note: that the .cpp generated by rcc is well taken into account by the compilation chain.
    However, the pixmap does not appear in place of the label.

    Qt may dislike the ICO format. Never mind, I converted to PNG.
    Still nothing but a construction error since each time the pixmap, QLabel:: pixmap () -> isNull () is true.

    I give up the resource file to associate the file directly. Ico to my label.
    And then I'll give you a thousand, it works!

    However, I missed something?? ... Or is it a bug in Qt ? In any case, I saw nothing of this kind, reported.
    Last edited by didier; 15th September 2010 at 16:07.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: [Qt 4.6.3] : pixmap resource for a label

    Surely the following is not correct:

    Qt Code:
    1. ": / icons / amber-on.ico "
    To copy to clipboard, switch view to plain text mode 
    It contains spaces where spaces should not be.

    Is this copy an paste?

  3. #3
    Join Date
    Sep 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [Qt 4.6.3] : pixmap resource for a label

    Yes, it's formatting during copy/paste.
    I'm correcting the message.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: [Qt 4.6.3] : pixmap resource for a label

    One reason why a resource can not be found is because the prefix is wrong.

    Can you post the contents of your resource file please?

    Edit:
    Another problem might be QString::fromUtf8
    What happens if you leave that conversion out?

  5. #5
    Join Date
    Mar 2010
    Location
    Capelle aan den IJssel, Netherlands
    Posts
    24
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: [Qt 4.6.3] : pixmap resource for a label

    Did you build your imageformats plugins? If Qt cannot find them, loading the Pixmap will fail, leaving you with a isNull pixmap.
    You can find the them in the QT_DIR\plugins\imageformats folder. For ICO, there should be a qico(d)4.dll or .a/.so whatever ;p

    If you run the application stand-alone, you should include the plugin and add the "addLibraryPath" command in your app, so Qt can find the plugin.

  6. #6
    Join Date
    Sep 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [Qt 4.6.3] : pixmap resource for a label

    Quote Originally Posted by tbscope View Post
    One reason why a resource can not be found is because the prefix is wrong.

    Can you post the contents of your resource file please?
    I guess it is not useful because it's managed by Qt Designer : qt resource file, prefixes in .ui file and so on.

    Edit:
    Another problem might be QString::fromUtf8
    What happens if you leave that conversion out?
    Same thing : the code is generated by uic. I've nevertheless tryed without but without success.

  7. #7
    Join Date
    Sep 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [Qt 4.6.3] : pixmap resource for a label

    I've taken the decision to track step-by-step what happens in Qt run-time in this context. So, I've linked my executable against Debug Qt libraries.
    And I 've discovered the following :

    Qt Code:
    1. bool QImageReader::read(QImage *image)
    2. {
    3. if (!image) {
    4. qWarning("QImageReader::read: cannot read into null pointer");
    5. return false;
    6. }
    7.  
    8. if (!d->handler && !d->initHandler())
    9. return false;
    To copy to clipboard, switch view to plain text mode 
    (d is QImageReaderPrivate* and d->handler is QImageIOHandler*)

    d->handler being NULL pointer,

    hence, this method returns false and so on until returning to my own code line :

    Qt Code:
    1. stateIndicator->setPixmap(QPixmap(QString::fromUtf8(":/icons/green-off.png")));
    To copy to clipboard, switch view to plain text mode 

    Seems not to be a plugin problem since support of png format is native.

    So, what's the problem ? (Hehe, cause you're a noob ! )

    Thank for your answer.

  8. #8
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: [Qt 4.6.3] : pixmap resource for a label

    Can you please post the contents of your resource file?
    I think the prefix is wrong.

  9. #9
    Join Date
    Sep 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [Qt 4.6.3] : pixmap resource for a label

    Here it is :

    Qt Code:
    1. <RCC>
    2. <qresource prefix="icons">
    3. <file>green-off.png</file>
    4. </qresource>
    5. </RCC>
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Sep 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [Qt 4.6.3] : pixmap resource for a label

    I've tried with a small example and it works : a dialog box with a label and an arbitrary png image. Nevertheless, I've tested it with Qt 4.6.2 on Ubuntu plateform (My project is under Qt 4.6.3 and Windows).
    I have verified again the .qrc is well computed and linked with the target. And this is the case.
    I foresee tracing execution in order to compare what it is done or not for concluding.

    I keep you informed.

  11. #11
    Join Date
    Sep 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default [Solved] [Qt 4.6.3] : pixmap resource for a label

    Ok ! Found !
    The reason is explained in "Qt Resource system" chapter.

    If you have resources in a static library, you might need to force initialization of your resources by calling Q_INIT_RESOURCE() with the base name of the .qrc file. For example:

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);
    Q_INIT_RESOURCE(graphlib);
    ...
    return app.exec();
    }


    Thank alll for your help.
    I hope my trouble will help you too.

Similar Threads

  1. Change the size of pixmap in a label
    By metRo_ in forum Qt Programming
    Replies: 16
    Last Post: 1st June 2012, 10:21
  2. label - pixmap - problem
    By qwrhiobasdbgghoasdf in forum Newbie
    Replies: 5
    Last Post: 16th September 2010, 00:29
  3. XML resource is garbled?
    By space_otter in forum Qt Programming
    Replies: 8
    Last Post: 22nd June 2010, 01:09
  4. How do i change images? Qt creator label>pixmap
    By QueenZ in forum Qt Programming
    Replies: 4
    Last Post: 8th February 2010, 04:44
  5. Qt Resource and StyleSheet Help
    By Peter_APIIT in forum Newbie
    Replies: 0
    Last Post: 19th September 2009, 06:25

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.