PDA

View Full Version : QObject->setParent() (sort of) freezes part of main interface.



xtothat
12th April 2011, 18:38
Hi folks!

I'm having a problem with a Qt4/C++ app that I'm writing.

I've created a custom class by subclassing QObject, in order for it to be able to use functions from my main application. I was hoping to use setParent to allow it to access my app's public functions via qobject_cast, which seems to work fine. However... while I have the QObject subclass's parent set as the main application, I can't click on, but can tab through 2 out of the three widgets on my main application. The other one I can click on and use absolutely fine. The others appear to work absolutely as expected, other than not being clickable.

The whole application works absolutely fine if I don't use setParent, and don't try to access the main class's functions.

Does anybody have a clue what on earth is going on here? I'm massively confused!

Thanks in advance for any help guys!!

X-T

aamer4yu
12th April 2011, 18:56
May be you can show some code,,,
from what you said, may be setting the parent is passing the events to parent first and it ignores them..:rolleyes:

xtothat
12th April 2011, 21:09
I've actually managed to sort it, thanks to going to copy and paste my subclass code here! Classic example of PEBKAC (Problem Exists Between Keyboard And Chair). I had apparently at some point changed my subclass to inherit from QWidget instead of QObject for some reason (I think because a QWidget's constructor optionally takes a parent argument). I changed it back to inherit from QObject, and now it works without fault! I'm assuming this is something to do with the differing ways in which QWidgets and QObjects handle events, as you say.

Sorry to waste your time, my friend; I'll look at my code more carefully before posting next time!

X-T