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.
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.
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?
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.
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.
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?
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.
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?
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..
Bookmarks