Important: Please read the Qt Code of Conduct -

QPushButton setIcon make application crash with no error message.

  • Hi,
    I need to change icons of pushbuttons in my gui... i'm using this code:


    where NUL is my PushButton ande image is a QImage. I've already verified the image is correctly loaded. On Qt 5.12.2 in windows with MinGW 7.3.0 32bits, that instruction SOMETIMES makes the program crash with no error message. Debugging the application says "segmentation fault" on that line, but also, no further error message to help me.

    Te same application runs perfectly on Linux compiling it with GCC. IDK what can i do to solve it, as i have no error messages.

    Any hints of what can i do to discover what is happening?

  • @dokif
    Please split your single line into 3 separate ones, with check for each function result. Surely it will simplify if we are sure which statement is actually segmenting, don't you think?

  • @dokif

    Maybe the use of QImage instead of QIcon will work?! Maybe there is something wrong with the conversion from QImage to QIcon... Just a guess...

  • @JonB : I've already tryed that, i can see there is content in both images and icon, and it fails anyway.

    Thanks for your answers...
    IDK why, but using the heap for storing the QImage worked for Windows. In linux it was not necessary.. I'm sure i'm making another mistake, but this works for me now.

Log in to reply