Home > Mobile >  The use of global variables in QT
The use of global variables in QT

Time:09-20

Recently found that the use of global variables, some don't understand, hope to be able to get advice, took good grateful

CodePudding user response:

Own a problem derived from the operating system on the little things like the SDK installation

CodePudding user response:

The method of Qt has its own global variables:
Q_GLOBAL_STATIC
Define a global static instance,

CodePudding user response:

It still need more reading, more to knock code, more understanding

CodePudding user response:

I was like this:

config. H
 
The namespace test {
Extern int WIDTH;
}


The config. CPP
 
The namespace test {
Int WIDTH=100;
}


Other documents in the # include "config. H"
Can use the
The test: : WIDTH

CodePudding user response:

Yang: hello,
thank you for your guidanceThis definition is written in a class can directly with global?

CodePudding user response:

Hello, administrator that this value is every time to restart the program is 100? What if other changes to make it into a value

CodePudding user response:

C + + does not support across files (CPP) global variables,
In the MainWindow. CPP in the constructor definition and assignment, can be used in other files, but not with the variable
MainWindow: : MainWindow (QWidget * parent)
: QMainWindow (parent)
, the UI (new UI: : MainWindow)
{
The UI - & gt; SetupUi (this);
a=0;//a are already in the header file public statement
}

At this point a can be invoked in other CPP, fixed and has the value 0, even if the MainWindow. CPP in subsequent assignment of a
Other CPP calls a remains unchanged,
  •  Tags:  
  • Qt
  • Related