Using QList data from other .cpp file
Hi, i'm trying to plot a graph in mainwindow.cpp using some data which i've processed and stored in a QList in another cpp file.
I've tried to include the header file of the cpp file i've processed in and declared the QList globally ( such as "QList<FinalData> finaldata") at the top of the mainwindow.cpp but the graph is not showing anything. I've tried to plot some random graph using random numbers and some graph is shown. Thus, i believe that i've not brought any data from the other cpp file to the mainwindow.cpp for plotting.
It may sound basic but is there anything wrong with what i'm doing and how can i bring over the data i've stored in a QList for plotting?
Any help will be appreciated. Thanks
Re: Using QList data from other .cpp file
As you are able to compile and run the program, there no porblem for linker to link to the QList variable symbol.
Next are you sure that the QList is already populated before you the paint/plot in the mainwindow?
Re: Using QList data from other .cpp file
I'm sure the QList is populated as i've tried to print out the data in the QList using qDebug in the cpp file which i've processed the data.
is it correct to declare the QList globally at the top of mainwindow.cpp in this format?
"QList<FinalData> finaldata"
i've tried this method in the same cpp file and it allows me to use data from one QList i've stored in a function and use it in another function. nut i'm not sure if it works across cpp files.
in addition, if i declare "QList<FinalData> finaldata" in my orignal cpp, i'll not be able to declare the same thing in my mainwindow.cpp, so i declare another called "QList<FinalData> finaldata1"
Re: Using QList data from other .cpp file
Are you referring to the same QList from both processingfile.cpp and mainwindow.cpp?
Also you should declare as "QList<FinalData> finaldata" in processingfile.cpp
and
declare as "extern QList<FinalData> finaldata" in mainwindow.cpp, note the extern keyword.
Quote:
I'm sure the QList is populated as i've tried to print out the data in the QList using qDebug in the cpp file which i've processed the data.
You need to check/print the QList just before the painting/plotting in the mainwidow.cpp
Re: Using QList data from other .cpp file
the word "extern" did the job and solved my problem. Thanks so much.