PDA

View Full Version : Global Qt Objects



SuperFun
19th March 2015, 18:00
Is there any danger in having a global object that uses Qt classes? Is there anything in the Qt framework that needs to be initialized before using classes such as QString or QHash?

Some customers have crashes at startup before entering main() where the QApplication object is created. For those that it happens to, it happens every time. Sending them a rebuild of the same code seems to fix the problem. Very strange. For other people it seems to never happen.

I already understand the risks and benefits of using global objects in general. I'm just wondering if Qt classes can be used in global objects since they are instantiated before the QApplication is created.

jefftee
19th March 2015, 19:39
I am not aware of any restrictions regarding global Qt objects. I have successfully used a QFile global object w/o any problems. As I'm sure you are aware, you should synchronize access to global objects.

Perhaps other may know if there are restrictions with QString or QHash, etc.

wysota
19th March 2015, 20:38
As long as you are not using anything that requires an instance of QApplication then you are ok. Widgets are not ok, pixmaps are not ok and anything that uses plugins is not ok. QHash and QString are definitely ok :)

SuperFun
27th March 2015, 19:42
Ok, thanks for weighing in everyone. That's what I could determine too since Qt is meant to be a library and not just for GUI application. I'll post here if I learn anything new.