Results 1 to 4 of 4

Thread: Global Qt Objects

  1. #1
    Join Date
    Mar 2015
    Posts
    2
    Thanks
    2
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Global Qt Objects

    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.

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Global Qt Objects

    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.

  3. The following user says thank you to jefftee for this useful post:

    SuperFun (27th March 2015)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Global Qt Objects

    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
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    SuperFun (27th March 2015)

  6. #4
    Join Date
    Mar 2015
    Posts
    2
    Thanks
    2
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: Global Qt Objects

    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.

Similar Threads

  1. how to use a global vars in QT?
    By wter27 in forum Qt Programming
    Replies: 5
    Last Post: 21st January 2011, 09:26
  2. How to specify my own global typedefs
    By Gert van Kruiningen in forum Qt Programming
    Replies: 7
    Last Post: 20th January 2011, 05:11
  3. Overriding global new
    By branko in forum Qt Programming
    Replies: 2
    Last Post: 19th October 2010, 16:10
  4. Replies: 3
    Last Post: 9th January 2010, 15:47
  5. Replies: 7
    Last Post: 18th July 2006, 21:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.