Results 1 to 4 of 4

Thread: sharing struct data throughout program

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    43
    Thanked 3 Times in 3 Posts

    Default Re: sharing struct data throughout program

    thanx JPN. Here's what i did based on your advice and looking around a bit on the web: first, I removed the "Comp" struct from the "Window" constructor function (above) and have created a new class in separate files:

    dafo.h
    Qt Code:
    1. #ifndef DAFO_H
    2. #define DAFO_H
    3.  
    4. class Dafo
    5. {
    6.  
    7. private:
    8. static short dataNUM_TOTc;
    9. //other variables.......
    10.  
    11. public:
    12. Dafo();
    13. ~Dafo();
    14.  
    15. //GETs
    16. static short get_dataNUM_TOTc() { return dataNUM_TOTc; }
    17.  
    18. //SETs
    19. static void set_dataNUM_TOTc(short value) { dataNUM_TOTc = value; }
    20.  
    21. };
    22.  
    23. #endif
    To copy to clipboard, switch view to plain text mode 

    I initialize the private variables in dafo.cpp like so:
    Qt Code:
    1. #include "dafo.h"
    2.  
    3. short Dafo::dataNUM_TOTc = 7;
    4. // other variables
    5.  
    6. Dafo::Dafo(void){
    7. }
    8.  
    9. Dafo::~Dafo(){
    10.  
    11. // delete this;
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

    ...and that's it. Now I can access get/set member functions of Dafo from any class-file which includes: #include "dafo.h"

    Anyway, pretty basic C++ I guess, but I thought I would post this in case I've made some obvious C++ programming/protocol mistakes that someone might point out.

    thanks again
    Last edited by vonCZ; 9th July 2007 at 17:38.

Similar Threads

  1. Replies: 16
    Last Post: 23rd May 2008, 10:12
  2. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 04:19
  3. program for working with Data Base(i need it)
    By banakil in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2007, 22:58
  4. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53

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
  •  
Qt is a trademark of The Qt Company.