I made in private, like you, but still isn´t work. While I use a method m.zapisz(51), value 51 is in bit2, or m.bit2? Because if in m.bit2, mainwindow.cpp can´t see this value :/
I made in private, like you, but still isn´t work. While I use a method m.zapisz(51), value 51 is in bit2, or m.bit2? Because if in m.bit2, mainwindow.cpp can´t see this value :/
As a general note, don't define static variables in header files, as each .cpp file which includes the header will get its own copy of the variable.
Typically you only declare the variable in header:
and define it in exactly one .cpp file:Qt Code:
// header.h extern int my_var;To copy to clipboard, switch view to plain text mode
In your case I suggest not using the global variable at all anyway.Qt Code:
// impl.cpp #include "header.h" int my_var = 0;To copy to clipboard, switch view to plain text mode
Hi, Iḿ not sure I understand you.
I should write extern int bit in private section in mainwindow.h?
And then, where I should write this:
// impl.cpp
#include "header.h"
int my_var = 0;
impl.cpp is my main.cpp or mainwindow.cpp? and int my_var is my bit?
No no, just do that as @jefftee suggested - remove the static variable completely. Use only member variable in the MainWindow class.I should write extern int bit in private section in mainwindow.h?
I mentioned the "extern" keyword as a sidenote, so that you know it for future.
Ok, i did it how @jefftee show, but still doesn´t work how I want :/ In main.cpp i have w.zapisz(51), so bit should have value 51, but in mainwindow.cpp bit don´t have a value :/
Are you sure you are reading the variable after your wrote to it?
Cheers,
_
Repost your current code for all of main.cpp, MainWindow.cpp, and MainWindow.h.
I write the best type of code possible, code that I want to write, not code that someone tells me to write!
Bookmarks