Results 1 to 20 of 29

Thread: Passing Pixmaps between MainWindow and Dialog

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2007
    Posts
    32
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Passing Pixmaps between MainWindow and Dialog

    Hello again wysota,

    Thanks for replying.
    I tried to get a backtrace but gdb told me there were 'No Backtrace.'. And yup, its already compiled in debug mode.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Passing Pixmaps between MainWindow and Dialog

    In that case it probably didn't crash or you did something incorrectly. Could you explain step by step what you did and what results you get after each step starting from launching the application?

  3. #3
    Join Date
    Dec 2007
    Posts
    32
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Passing Pixmaps between MainWindow and Dialog

    Ok..Before I run gdb I navigate first to the directory where the program is located.

    1. In the console, I type gdb then proceed with "pwd" command to double check the working directory.
    <gdb> -> Working directory ....
    2. I type "file GUI.exe" then press return
    <gdb> -> Reading symbols from gui.exe .. done.
    3. I type "run" then press return
    <gdb> -> Starting program ...
    4. In the program, I use the file dialog to select a jpeg image in My Documents folder.
    5. After loading, the picture, my program responds with a Info box.
    <gdb> -> Still blank..
    6. Then I use the Adjust Brightness option from the Tools Menu.
    7. Program quits unexpectedly.
    <gdb> -> Program exited with code 01.
    8. I type "bt".
    <gdb> -> No stack.

  4. #4
    Join Date
    Dec 2007
    Posts
    32
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Passing Pixmaps between MainWindow and Dialog

    I didnt get a segmentation fault btw..

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Passing Pixmaps between MainWindow and Dialog

    Quote Originally Posted by ramstormrage View Post
    I didnt get a segmentation fault btw..
    Yes, I can see that. My guess is your program asserted. It seems you didn't build it in debug mode (in terms of debugging info being embedded into your app) after all. Please double check that. You can set a breakpoint in the function you expect to cause problems and manually step through the code to see where it breaks.

  6. #6
    Join Date
    Dec 2007
    Posts
    32
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Passing Pixmaps between MainWindow and Dialog

    Hello again, Thanks for replying..
    Ok I'll try that..

    Anyways, my previous hunch was right, the QImage image object gets destroyed after the MainWindow:pen() function. In the showBrightnessDialog(), I tried to put another
    QImage image(fileName); and it proceeded and displayed the pixmap inside the label as planned.

    Just to need know why? Any ideas?

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Passing Pixmaps between MainWindow and Dialog

    If the image object was going out of scope, you wouldn't be able to compile the application. It's not a heap based object, it can't be deleted "somewhere in the meantime". The image might be null, but that by itself wouldn't cause your application to crash unless you tried to iterate its pixels or something.

  8. #8
    Join Date
    Dec 2007
    Posts
    32
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Passing Pixmaps between MainWindow and Dialog

    Quote Originally Posted by wysota View Post
    It seems you didn't build it in debug mode (in terms of debugging info being embedded into your app) after all. Please double check that.
    Hello again,
    I need help again on this one.
    If I need to build the application in debug mode, I should include -g flag during compilation right? But I let qmake do the compiling for me.

    This is how i compile my program in debug mode (after I Built Debug Libraries)
    qmake -project
    qmake GUI.pro "CONFIG+=debug"
    make

    Am I doing something wrong?

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Passing Pixmaps between MainWindow and Dialog

    No, it's fine. You can check if the resulting makefile has proper flags, if you want to be sure. I really suggest you try stepping through the code from within the debugger.

  10. #10
    Join Date
    Dec 2007
    Posts
    32
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Passing Pixmaps between MainWindow and Dialog

    EDIT: Sorry, I stepped through the program, I found that the program halts somewhere within this function.

    void brDialog::createImage(QImage &imag)
    {
    beforeLabel->setPixmap(QPixmap::fromImage(imag));
    imagafterRGB = fileHandler.convertToRGBImage(imag);

    //imagafter = fileHandler.convertToQImage(imagafterRGB);
    afterLabel->setPixmap(QPixmap::fromImage(imagafter));
    }


    DOUBLE_EDIT:
    Hello wysota,

    I traced the program for a while and I experimented on different codes, and I found that the QImage image object from a while back really gets destroyed if i dont reinitialize it with QImage image(fileName) before I pass it to brDialog::createImage()

    Now the problem is why? And is there another way to avoid this without reinitializing the image object?


    Qt Code:
    1. void MainWindow::adjustBrightness()
    2. {
    3. brDialog dialog(this);
    4. //QImage image(fileName); <-- can I avoid this or maybe I dont have a choice?
    5. dialog.createImage(image);
    6. dialog.exec();
    7. }
    To copy to clipboard, switch view to plain text mode 


    Thank you for your patience..
    Last edited by ramstormrage; 19th April 2008 at 16:42. Reason: updated contents

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Passing Pixmaps between MainWindow and Dialog

    Find out where you lose your image. It's certainly somewhere before adjustBrightness is called. Currently you don't "reinitialize" the image but create a local variable with the same name. If you do the same elsewhere then simply your member variable "image" never gets initialized.

  12. #12
    Join Date
    Dec 2007
    Posts
    32
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Passing Pixmaps between MainWindow and Dialog

    Quote Originally Posted by wysota View Post
    If you do the same elsewhere then simply your member variable "image" never gets initialized.
    So that means its not correct to use QImage image(QString fileName) whenever I need to pass images to dialogs?

    Is there another way to "permanently" initialize a QImage object from a file?

    EDIT:
    Hmm, I cant seem to find where in the code does the image object get lost, you see, I tried to clear and repaint the image on QLabel imageLabel until the end of MainWindow:pen(), and it still exists.

    And then I tried to repaint the image inside the below function, just to try if image is still valid, and it is..

    Qt Code:
    1. void MainWindow::closeImage()
    2. {
    3. imageLabel->clear();
    4. closeAction->setEnabled(false);
    5. imageLabel->setPixmap(QPixmap::fromImage(image));
    6. }
    To copy to clipboard, switch view to plain text mode 

    Now in my current project, these are the only functions inside the mainwindow.cpp file:
    1. constructor
    2. createMenus()
    3. createActions()
    4. open()
    5. closeImage()
    6. adjustBrightness()

    I cant seem to find where image gets lost.
    Last edited by ramstormrage; 19th April 2008 at 18:16. Reason: updated contents

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Passing Pixmaps between MainWindow and Dialog

    Quote Originally Posted by ramstormrage View Post
    So that means its not correct to use QImage image(QString fileName) whenever I need to pass images to dialogs?
    Yes, that's correct - it's incorrect.

    Is there another way to "permanently" initialize a QImage object from a file?
    Substitute
    Qt Code:
    1. QImage image(filename)
    To copy to clipboard, switch view to plain text mode 
    with
    Qt Code:
    1. image = QImage(filename);
    To copy to clipboard, switch view to plain text mode 

  14. The following user says thank you to wysota for this useful post:

    ramstormrage (20th April 2008)

  15. #14
    Join Date
    Dec 2007
    Posts
    32
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Passing Pixmaps between MainWindow and Dialog

    Finally!!

    After 25 posts, we got the correct code! Thanks for the help.. I cant thank you enough..
    Haha!
    Now, to do something about this blasted HEAP problems Ive been getting..

Similar Threads

  1. Communication between MainWindow and a dialog
    By Backslash in forum Newbie
    Replies: 9
    Last Post: 3rd August 2007, 04:27
  2. Replies: 2
    Last Post: 23rd May 2007, 03:51
  3. Opening a Dialog from a MainWindow FileMenu
    By nbkhwjm in forum Newbie
    Replies: 4
    Last Post: 17th April 2007, 12:24
  4. Replies: 3
    Last Post: 23rd July 2006, 18:02

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.