[SOLVED] Qt crashing on windows when loading an image file

  • hello,

    This is my first topic here, so I apologize beforehand if I'm using the wrong forum.

    I'm having an issue with loading an image file into a QWidget object. Basically what I'm trying to do is set the background of a widget to a certain gif file.

    This is my code:

    #include "loginwindow.h"
    #include "ui_loginwindow.h"
    #include <QImage>
    #include <QLabel>

    LoginWindow::LoginWindow(QWidget *parent) :
    ui(new Ui::LoginWindow)

    ui->logo->setStyleSheet("QWidget {background-image: url(C:\\Users\\Dell1\\Desktop\\QtProjects\\test\\pic.jpg) }");



    delete ui;


    The above code compiles but when trying to run it, I get a windows error (untitled.exe has stopped working).
    Untitled being the bane of my project. The project runs fine when I comment out the "ui->logo->setStyleSheet...." line.

    I tried using QPixmap with a QLabel and it gave me the same runtime error.

    I'm using Qt 2.0.1 on a Windows 7 OS (32 bit). I checked all the Qt plugins and they seem intact.

    Is there something wrong with the code ? Am I missing something ?

    Any help or hints would be appreciated.


    [edit : next time please use @ tags for your code, thanks, Eddy]

  • Place ui->setupUi(this); on the top of the constructor.

  • Yup. It did it. What a dumb mistake!
    Thank you, much appreciated. :)

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.