Global variable in Qt, how to?


Question

I'm using Qt and in the main method I need to declare an object that I need to use in all my other files. How can I access that object in the other files? (I need to make it global..)

I'm use to iPhone development and there we have the appDelegate that you can use all over the application to reach objects you've declared in applicationDidFinishLaunching method. How can I do the same in Qt?

1
7
9/24/2009 9:13:32 PM

global_objects.hpp

extern int myGlobalInt;

global_objects.cpp

#include "global_objects.hpp"

namespace
{
    int myGlobalInt;
}

And then #include "global_objects.hpp" in every place you need myGlobalInt.

You should read C++ singleton vs. global static object and Initializing qt resources embedded in static library as well.

9
5/23/2017 12:19:06 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon