Results 1 to 5 of 5

Thread: Issue with QPixmap in Qt 3.2.1

  1. #1
    Join Date
    Feb 2006
    Posts
    7
    Qt products
    Qt3
    Platforms
    Windows

    Default Issue with QPixmap in Qt 3.2.1

    Hi, I am trying to get an image to display on a button. The code belows does the job

    void Form1::init() {
    pushButton1->setPixmap(QPixmap::fromMimeSource("ulquarter4.jpg "));
    .
    .
    .
    }

    However, I'd like to be able to use a pixmap variable instead. After declaring QPixmap *Pixmap 1 as a private member, I tried the following:

    void Form1::init() {
    *Pixmap1 = QPixmap::fromMimeSource("ulquarter4.jpg);
    pushButton1->setPixmap(*Pixmap1);
    .
    .
    .
    }

    It compiled without errors in the command prompt, but when I tried to execute it, I got a popup dialog box declaring that there was an error trying to open the executable.

    Can anyone help me?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Issue with QPixmap in Qt 3.2.1

    Did you initialize that Pixmap1 variable or did you left it as a dangling pointer?

  3. #3
    Join Date
    Feb 2006
    Posts
    7
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Issue with QPixmap in Qt 3.2.1

    Quote Originally Posted by jacek
    Did you initialize that Pixmap1 variable or did you left it as a dangling pointer?
    Is this line in the init() function not the same thing as initializing it?

    *Pixmap1 = QPixmap::fromMimeSource("ulquarter4.jpg");

    Please note that I am new to Qt Designer...I've been using it for only a few days now.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Issue with QPixmap in Qt 3.2.1

    Quote Originally Posted by filmfreak
    Is this line in the init() function not the same thing as initializing it?

    *Pixmap1 = QPixmap::fromMimeSource("ulquarter4.jpg");
    No, because you first dereference that pointer. You need something like this:
    Qt Code:
    1. Pixmap1 = new QPixmap(); // initialize Pixmap1 and make it point to a null pixmap
    2. *Pixmap1 = QPixmap::fromMimeSource("ulquarter4.jpg"); // fill that null pixmap with new data
    To copy to clipboard, switch view to plain text mode 
    Although it will be much easier, if you just use QPixmap instead of QPixmap *.

    Please note that I am new to Qt Designer...I've been using it for only a few days now.
    It has nothing to do with Qt Designer or ever Qt itself --- it's C++ issue.

  5. #5
    Join Date
    Feb 2006
    Posts
    7
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Issue with QPixmap in Qt 3.2.1

    Thanks, I think that solved the problem.

Similar Threads

  1. QPixmap and HBITMAP
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2006, 16:24

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.