Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. One header file to be used only once in whole program
Forum Updated to NodeBB v4.3 + New Features

One header file to be used only once in whole program

Scheduled Pinned Locked Moved Unsolved C++ Gurus
2 Posts 2 Posters 394 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Thank YouT Offline
    Thank YouT Offline
    Thank You
    wrote on last edited by
    #1

    I have header file named
    simple.h
    Suppose with messageBox and one variable calledVariable fetched from database in constructor
    (THIS VARIABLE IS NEVER GONNA CHANGE)

    It is used in another header file
    name.h

    And this header file is used in many files

    #include"simple.h"
    

    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

    Let's make QT free or It will go forever

    TRUE AND FALSE <3

    jsulmJ 1 Reply Last reply
    0
    • Thank YouT Thank You

      I have header file named
      simple.h
      Suppose with messageBox and one variable calledVariable fetched from database in constructor
      (THIS VARIABLE IS NEVER GONNA CHANGE)

      It is used in another header file
      name.h

      And this header file is used in many files

      #include"simple.h"
      

      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

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved