Results 1 to 11 of 11

Thread: global variable

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: global variable

    Quote Originally Posted by Shuchi Agrawal View Post
    i m declaring freebytes, usedbytes variables in globalvar.h
    First of all you should avoid global variables as they can cause a lot of troubles. Secondly, you shouldn't define variables in header files, because every .cpp file that includes such header will have its own copy of those variables.

    If you really want to use global variables you should do it this way:
    Qt Code:
    1. // globalvar.h
    2. ...
    3. extern int freebytes;
    4. extern int usedbytes;
    5. ...
    6.  
    7. // globalvar.cpp
    8. int freebytes = 0;
    9. int usedbytes = 0;
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to jacek for this useful post:

    Shuchi Agrawal (13th February 2007)

Similar Threads

  1. Qt and global variables
    By Morea in forum Qt Programming
    Replies: 11
    Last Post: 1st February 2007, 23:42
  2. saving a c string of variable length in a shared memory?
    By nass in forum General Programming
    Replies: 4
    Last Post: 3rd January 2007, 14:40
  3. custom plugin designer property with out a variable?
    By high_flyer in forum Qt Programming
    Replies: 1
    Last Post: 15th March 2006, 19:11
  4. Creating a global array in my code???
    By therealjag in forum General Programming
    Replies: 5
    Last Post: 13th March 2006, 11:13
  5. declaration of global variables???
    By pranav_kavi in forum Newbie
    Replies: 6
    Last Post: 31st January 2006, 19:56

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.