PDA

View Full Version : Using QList data from other .cpp file



kango
13th February 2013, 16:05
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

Santosh Reddy
13th February 2013, 16:15
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?

kango
13th February 2013, 16:27
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"

Santosh Reddy
13th February 2013, 16:59
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.


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

kango
13th February 2013, 17:31
the word "extern" did the job and solved my problem. Thanks so much.