Results 1 to 2 of 2

Thread: Passing QImage Pointers to Dialogs

  1. #1
    Join Date
    Nov 2010
    Posts
    23
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    2

    Default Passing QImage Pointers to Dialogs

    Hey everyone,

    I'm trying to pass a QImage pointer to a dialog window I use to open image files. The reasoning for this is to prevent memory leak.

    A snippet of code looks like:
    Qt Code:
    1. OpenDialog::OpenDialog(QWidget *parent, QImage *imageA, QImage *imageB)
    2. : QDialog(parent)
    3. {
    4. qDebug() << imageA;
    5. loadClicked();
    6. }
    7.  
    8. void OpenDialog::loadClicked()
    9. {
    10. qDebug() << imageA;
    11. }
    To copy to clipboard, switch view to plain text mode 

    which is initialized with:
    Qt Code:
    1. QImage *imageA_display = 0;
    2. QImage *imageB_display = 0;
    3. openDialog = new OpenDialog(this,imageA_display,imageB_display);
    To copy to clipboard, switch view to plain text mode 

    This is a small section, but it illustrates the problem... when qDebug is called the first time, it prints out 0x0 since I have it initialized to an null pointer. The program wont compile when loadClicked is introduced ('imageA was not declared in this scope'). Do variables given to the constructor become global variables? If so then how is imageA not in the scope?

    Thanks for all the help in advance!!

  2. #2
    Join Date
    Sep 2010
    Posts
    145
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1
    Thanked 18 Times in 17 Posts

    Default Re: Passing QImage Pointers to Dialogs

    Constructor parameters are local to the constructor body. You need a member to contain the pointer. You should look into smart pointers...and an entry level book on c++.

Similar Threads

  1. Problem with passing Pointers to a Slot
    By Basti300 in forum Newbie
    Replies: 2
    Last Post: 26th May 2010, 15:45
  2. Translation of app and Qt Dialogs
    By honza in forum Qt Programming
    Replies: 4
    Last Post: 11th May 2009, 18:53
  3. Problems passing an array of pointers to objects to a function
    By Valheru in forum General Programming
    Replies: 16
    Last Post: 30th June 2008, 01:11
  4. Skinned dialogs
    By Lele in forum Qt Programming
    Replies: 24
    Last Post: 9th August 2007, 09:43
  5. Replies: 3
    Last Post: 15th March 2006, 12:44

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
  •  
Qt is a trademark of The Qt Company.