PDA

View Full Version : Serious bug on dialog->isVisible (returns 1 but it is not visible!)



hakermania
5th December 2010, 13:03
That's the code:


if(Screenshot->isVisible())
{ //we don't want duplicates of the screenshot dialog so point to the already visible
system("echo 1 > /home/alex/Desktop/IF"); //I placed this to check from where it goes when it crashes
Screenshot->raise();
Screenshot->activateWindow();}
else
{ //show the screenshot dialog
system("echo 1 > /home/alex/Desktop/ELSE"); //I placed this to check from where it goes when it crashes
Screenshot = new screenshot(this);
Screenshot->exec();
}

Sometimes this opens normally and some other times it crashes. I tried to find out what the problem was and i realized that when the program crashes Screenshot->isVisible() returns 1 and so goes to the "if" and that's why it crashes(it takes Screenshot->raise() but Screenshot dialog is not visible so it crashes)

This is very serious. I am 100 % sure that the error is because of screenshot->isVisible() ( because as you see at the code I placed a system("echo 1 > /home/alex/Desktop/IF"); at the "if" occasion and a system("echo 1 > /home/alex/Desktop/ELSE"); at the "else" occassion and everytime the program crashed the IF file was appearing! so screenshot->isVisible() is quite buggy!). I know that we are told not to be against QT but I don't know how else to explain that Screenshot->isVisible() returns 1 while screenshot dialog is not visible. The most strange thing is that only 1/5 times the program crashes, the other times the screenshot dialog opens normally! So these 2 things forced me to believe that it is a QT bug.

But in any occassion, any suggestion? :crying:

Added after 10 minutes:

And not only this. All of Screenshot->isEnabled() && Screenshot->isVisible() && Screenshot->isTopLevel() turn to be buggy and return 1 in this occassion

squidge
5th December 2010, 13:18
Why don't you set Screenshot to NULL by default? That if it's not null you know you have created it so you can just use raise() and therefore no need for isVisible() (which I think just returns an interval variable - it has no idea if other windows are on top of your dialog)

Unless of course I've just completely mis-interpreted your post.

hakermania
5th December 2010, 14:39
This could be a solution:

if(screen_is_on) return;
screen_is_on=1;
Screenshot = new screenshot(this);
Screenshot->exec();
screen_is_on=0;
Except from if(screen_is_on) return; I can use if(screen_is_on){
Screenshot->raise();
Screenshot->activateWindow();
}

wysota
5th December 2010, 16:23
And not only this. All of Screenshot->isEnabled() && Screenshot->isVisible() && Screenshot->isTopLevel() turn to be buggy and return 1 in this occassion

The common denominator of all this is the "Screenshot" object which is the one that is truly buggy. You are using an uninitialized variable so calling any method of the object will result in a crash.

hakermania
5th December 2010, 17:12
And how do you explain that this is happening 1/5 and not every time ?

wysota
5th December 2010, 17:23
And how do you explain that this is happening 1/5 and not every time ?

I won't even try explaining it, it's your task - take your source code, debugger and find out.