Results 1 to 5 of 5

Thread: Using QList data from other .cpp file

  1. #1
    Join Date
    Jan 2013
    Posts
    17
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default 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?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jan 2013
    Posts
    17
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default 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"
    Last edited by kango; 13th February 2013 at 17:33.

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default 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.

    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
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. The following user says thank you to Santosh Reddy for this useful post:

    kango (13th February 2013)

  6. #5
    Join Date
    Jan 2013
    Posts
    17
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using QList data from other .cpp file

    the word "extern" did the job and solved my problem. Thanks so much.

Similar Threads

  1. QList of variable data type?
    By Phlucious in forum Qt Programming
    Replies: 13
    Last Post: 2nd December 2011, 01:25
  2. Replies: 3
    Last Post: 8th June 2011, 07:36
  3. How to view data stored in Qmap or QList
    By sankar in forum Newbie
    Replies: 6
    Last Post: 17th February 2011, 10:30
  4. QList custom data format
    By sureshkvl in forum Qt Programming
    Replies: 1
    Last Post: 13th October 2010, 14:26
  5. Replies: 4
    Last Post: 20th August 2010, 14:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.