Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QLabel with the QPixmap blues



  • I am using a QLabel pixmap as an indicator for connection to a database. I load the pixmap with a disabled png so that I can see the results easier. My code is;

    sl1 = new QLabel(this);
        sl2 = new QLabel(this);
        QPixmap dbOFF(":/32/32_072");
        QPixmap dbON(":/32/32_073");
        ui->mainSB->addPermanentWidget(sl1,50);
        sl1->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        ui->mainSB->addPermanentWidget(sl2,50);
        sl2->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        if (!ars.open())
            {
            ui->appDB->setPixmap(dbOFF);
            sl1->setText("DB Off");   //NOTE For testing Only
            }
        else
            {
            ui->appDB->setPixmap(dbON);
            sl1->setText("DB On");   //NOTE For testing Only
            }
    

    When the program runs my statusBar text is correct but the preloaded image is NOT displayed and appDB pixmap is blank. There must be a step I'm missing but I'm tto close to see it now, can someone help me out?


  • Lifetime Qt Champion

    Hi and welcome to the forums.
    The path/name seems a bit odd
    ":/32/32_072"
    as normally it would end in .jpg / .png etc.

    If you go to the resource file and and right click the image , what path/name does it show?

    alt text



  • Thanks for pointing that out. It was a copy error for the post and was correct in the actual file. Just to be sure, I ran it again and the results were the same. In Creator I added the disabled pixmap to the allDB QLabel. And it displayed fine. But when I compile and run appDB is a blank image. I must be leaving out something. I've checked several post on stackoverflow and saw several ways . But this way seemed to be correct.
    I'm trying to port some of my Borland C++Builder 6 work over to Open Source and this method seems to keep the cosmetic look the best so I really want to get this to work. If someone knows what I am doing wrong, don't tell me, just be a bird dog and point. I need the discovery part of this to stay intact. Otherwise, I'll just be another whiner looking for the easy way, I'm not that. And don't take it wrong what I said about being a dog. I want the challenge but I also have an eye on the clock. Thanks mrjj.



  • There really is not much to it.
    I'd check to make sure that dbON.isNull() is false.
    This will at least tell you if the pixmap is loading from the source.
    if dbON.isNull() is true, then double check (or in this case triple check) that the source path is correct.
    I'm assuming that ui->appDB is a QLabel ?



  • Yes, QLabel. Source path is correct. It must be in something I'm overlooking, like you say there is not much to it. Tomorrow is a new day. Thanks for your input. If all else fails, I'll do a stripped down project with just a QLabel and test my code there. Good Idea, thanks.



  • Ok. If dbOn.isNull() is false, then I'd check the width and height of it to see if it matches what is expected. If that all looks ok, then I'd extract the pixmap from the label after assigning it:
    const QPixmap *p = dbOn.pixmap();
    and then check "p" to see if has the expected dimensions.
    If worse comes to worse, make sure that the label is visible.
    Good luck.



  • 0_1524747493564_Screenshot from 2018-04-26 08-45-14.jpg

    Ok, they are both invalid. But I can still load them and display them during development so they are valid png and the resource link is valid so I'm not sure where to look next. To be invalid you would think it would be incorrectly formatted but it looks good to me. Any help decrypting this would be appreciated.


  • Lifetime Qt Champion

    That is a bit odd. Since ressources files are compiled into the exe,
    its hard for them to be invalid.
    if both path is correct and the images can be clicked and shown from within Creator
    they must be valid. Also compiles fails if files are missing.

    Could you try to delete the build folder complete and run qmake and then rebuild all.



  • Ok, this got my curious so I did some experimenting.
    On Windows (mine is 8.1) there does seem to be some problems with jpg files.
    I pulled a bunch of jpg's from various resources and found that whether they load is hit or miss.
    I'm guessing there is something in the imageformats plug in for windows that rejects some
    files. I don't know enough about the file formats to say why.
    One consistency I found is that if the windows image viewer will display the file, then the Qt app will load it. I have some jpgs that load in other applications, but not the Image Viewer or the Qt app.
    Try converting your image to a PNG and see if you get better results.
    <edit>
    After doing a little more research and dumping the binaries I've found that many images that are labeled as "jpg" are not really JPEGS. Some image readers have no problem with this but the Qt plugin probably does. One situation I found curious is that in QtCreator, I could highlight the resource path of the image and it would display, but not load....



  • Thanks for the responses. First, I did a Clean-All and the qmake, no difference. mranger90, I am developing and trageting Linux Ubuntu so window quarks, not really a problem. Also I use .png as my goto default format for images. Someone asked about the QPixmap being hidden so I change cpp to this...
    0_1524838427450_XX_cpp.png
    Then there's this...
    0_1524838489614_XX_Design.png
    So at run time I get this...0_1524838562776_XX_Run.png

    I would think of a corrupted .qrc file but it compiles with no errors. I'm thinking that there must be something with the way I'm calling for the Pixmap change that is at fault but everywhere I look they reference this method. Can anyone offer a different way? This project is in limbo until I find a way to get this to work. My original app. had numerous events where ToolBar Button icons would change to indicate the state of the classes they controlled. This just seemed to be an easier way.



  • At this point, all I can suggest is that you simplify.
    Write a really small app, say a dialog with just a QLabel,
    and and try to load your image into the QPixmap both as from an external file,
    and from the resource tree.



  • OK I did as you (and I) wanted and that was do a simple dialog and see what happens. So I built a simple Dialog project ON A DIFFERENT COMPUTER with different resources in the .qrc file and the results were exactly the same.

    0_1524963121314_BuildProb_001.png

    So I can only suspect that my method is in error. Can someone lend who or how I can resolve. Can someone do the same with a quick project and either confirm my results or, and I hope, show me my error(s). Thanks for all the support.


  • Lifetime Qt Champion

    Hi
    I cant guess what goes wrong. all seems fine. :)

    Sample here.
    https://www.dropbox.com/s/q41hgzc36xqx482/mycons.zip?dl=0

    expected result.
    alt text



  • PROBLEM SOLVED
    I want to thank mrjj for making a simple project "mycons". It was when I looked at his files and made a quick comparison that the solution jumped out at me. When he made his .qrc file he added icons that were in the root folder. I was porting over a Borland project and just used the same folders for graphics I used back then. They were in sub folders according to pixel size, '16' '24' and '32'. I just batched renamed the 32_XXX with size first then _sequential numbers. When I wanted to get the name I just looked in the .qrc and saw <file>32/32_072.png</file> so that is what I used. BUT the <file> line was wrapped in <qresource prefix = "/32"> </qresource>. So when I used :32/32_072.png as the QPixmap file, I should have been using :/32/32/32_072.png. At that time I became blind to the oversight and just went, off the deep end. This is why it is so hard to be a lone programmer, lesson learned. Thanks again mrjj its always the minutia that brings us to our knees. Thanks again to all that responded.


  • Lifetime Qt Champion

    @WillyBoy-0
    Hi, no troubles.
    Ah, that was somewhat sneaky.
    For the record, right clicking the image in project tree, shows the correct path or
    did it miss the extra 32 path part ?



  • Hi mrjj, hovering over an item in the .qrc file displays the raw computer location (again a mislead for me) but right click options are Creator's path (:/32/32/32_073.png) or the url (qrc:/32/32/32_073.png) just remove the qrc bit and that's what is needed.
    Very cool. One more sidebar, how do I mark this thread SOLVED? Again thanks, btw I'm moving to Florida in the coming weeks so I will have to suspend my project for awhile. But I plan to give renewed life to all 11 of my old Borland projects but most of them need some upgrades to compete today.


  • Lifetime Qt Champion

    @WillyBoy-0
    Hi
    On first post u made. In Topic tools. is way to say Solved.
    Oh, happy moving then.
    You will find that Qt does most of what VCL does/did.
    I hope its that new and not the good old OWL ;)



  • Yup, VCL! Most for what I did was local db (back then, Paradox 7, with the BDE) with focus on the Automotive Repair industry. With an offshoot to Independent Day Care Software for small to medium in-home sites. A sysbar app GotMail? for email notification (2003), outdated now. But I have stuff to keep me busy for awhile. I won't miss Pennsylvania winters, that's for sure!


  • Lifetime Qt Champion

    @WillyBoy-0
    Hehe i guess nobody would miss Pennsylvania winters :)

    To replace BDE, Sqlite might be handy. Qt has excellent support.
    (if needs are only local db)



  • In an earlier post you can see I've already committed to SQLite,. It seamed to be a logical choice and mirrors Paradox pretty close, as far as function. I've done MySQL both local and remote before and it's pretty straight forward and easy to use but I see it as a Mustang when a Escort will do. And besides, copy and paste is a DB backup dream.


Log in to reply