Read this global variables.
Read this global variables.
Misha R.evolution - High level Debugging IDE
Programming is about 2 basic principles: KISS and RTFM!!!
Thanks for your answer.I was thinking a Label is not a variable?
You should really read the whole C++ tutorial in the site I gave you, not just the part about global variables.
Misha R.evolution - High level Debugging IDE
Programming is about 2 basic principles: KISS and RTFM!!!
I have read it,that page doesn't recommend using global variables.But I need to access objects inside functions,how can I do it?
Create a interface in the class owning the label that lets you modify it in the way you want.
e.g: updateLabel(QString textForLabel)
{
//code to modify Label
}
then let your other class access the label through this function?
Declare them outside of main() or put them in a header file
but it is best not to use them where they can be avoided.
Qt Code:
#include <QtGui/QApplication> #include "mainwindow.h" #include "myglobals.h" // globals here int aInteger; int main(int argc, char *argv[]) { MainWindow w; w.show(); return a.exec(); }To copy to clipboard, switch view to plain text mode
Last edited by JD2000; 19th March 2010 at 13:59.
(Sorry for my late reply)
Thanks for your answers.
JD2000,I tried writing into "globals here section" but it gives an error.It works when I use it in a header file though.
Bookmarks