Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Qt crashing on windows when loading an image file
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hesperus
    wrote on last edited by
    #1

    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) :
    QWidget(parent),
    ui(new Ui::LoginWindow)
    {

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

    }

    LoginWindow::~LoginWindow()
    {

    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.

    Thanks.

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

    1 Reply Last reply
    0
    • P Offline
      P Offline
      p-himik
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hesperus
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved