Page 2 of 2 FirstFirst 12
Results 21 to 29 of 29

Thread: Passing Pixmaps between MainWindow and Dialog

  1. #21
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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.

  2. #22
    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

  3. #23
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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.

  4. #24
    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

  5. #25
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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 

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

    ramstormrage (20th April 2008)

  7. #26
    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..

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

    Default Re: Passing Pixmaps between MainWindow and Dialog

    Ok heap problems gone.

    I forgot to ask this earlier but how to do I pass the modified image back to the MainWindow?
    I created a method in MainWindow that accepts the modified image, but how do I call it from the dialog?

  9. #28
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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

    Oh come on, man. None of your problems are related to Qt - every problem you have is about C++ and code design. We are not here to teach you C++! Try making a method similar to the one I suggested in my very first post in this thread (or a second one, I don't remember) just going the other way round.

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

    ramstormrage (20th April 2008)

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

    Default Re: Passing Pixmaps between MainWindow and Dialog

    Ok thank you very much wysota, I learned plenty of stuff.

    Anyways, for the sake of other people that'll possibly view this thread, here's a possible solution.

    Qt Code:
    1. void MainWindow::adjust()
    2. {
    3. adjustDialog dialog(this); //Invoke modal Adjust Brightness Dialog
    4. dialog.createImage(image); //Pass current image object to dialog
    5. if (dialog.exec()){
    6. image = dialog.submitImg(); //Overwrite current image with mod. image
    7. refreshImage();
    8. }
    9. }
    10.  
    11. QImage adjustDialog::submitImg()
    12. {
    13. return ModifiedQImageObject; //Returns modified image to MainWindow
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ramstormrage; 20th April 2008 at 15:21.

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.