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.
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.
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:
void MainWindow::adjustBrightness() { brDialog dialog(this); //QImage image(fileName); <-- can I avoid this or maybe I dont have a choice? dialog.createImage(image); dialog.exec(); }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
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.
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:
void MainWindow::closeImage() { imageLabel->clear(); closeAction->setEnabled(false); }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
Yes, that's correct - it's incorrect.
Substitute withIs there another way to "permanently" initialize a QImage object from a file?
ramstormrage (20th April 2008)
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..
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?
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.
ramstormrage (20th April 2008)
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:
void MainWindow::adjust() { adjustDialog dialog(this); //Invoke modal Adjust Brightness Dialog dialog.createImage(image); //Pass current image object to dialog if (dialog.exec()){ image = dialog.submitImg(); //Overwrite current image with mod. image refreshImage(); } } { return ModifiedQImageObject; //Returns modified image to MainWindow }To copy to clipboard, switch view to plain text mode
Last edited by ramstormrage; 20th April 2008 at 15:21.
Bookmarks