Please nominate your Qt Champions for 2021!

One header file to be used only once in whole program

  • I have header file named
    Suppose with messageBox and one variable calledVariable fetched from database in constructor

    It is used in another header file

    And this header file is used in many files


    In 10 files.

    Here when I do this I get 10 message box with same thing. What I want is to
    call simple.h ONLY once. and get the same variable value calledVariable which we will get in the first execution

  • Lifetime Qt Champion

    @Thank-You Declare the variable es extern in the header file and define it once somewhere in a C++ file.
    See for details.
    But keep in mind that QObject based classes are not allowed to be instantiated before QApplication instance is created!

Log in to reply