Results 1 to 7 of 7

Thread: declaration of global variables???

  1. #1
    Join Date
    Jan 2006
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default declaration of global variables???

    Hi friends,

    I'm a beginner to Qt and in the current application that I'm developin on Linux,I have encounterd problem in using global variables.
    I ve a main.cpp,that has a declaration as follows,
    QString var;
    int main()
    {
    .....
    .....
    qDebug(var);
    }//end main
    In another file-BList.ui.h,I am using the 'var' variable and assigning it a value in one of its member fns.Part of the code is as follows,
    extern QString var;
    void BList::itemDoubleClicked()
    {
    .....
    var = "BUDDY";
    }//end fn
    When I run the project,the value of 'var',it is displayed as nothing...May I know what the problem is???
    Any help would be appreciated...

    Thanx & Rgards,
    Kavitha

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: declaration of global variables???

    How do you know that var is empty?
    It's nice to be important but it's more important to be nice.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: declaration of global variables???

    Are you sure this itemDoubleClicked() gets called?

  4. #4
    Join Date
    Jan 2006
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: declaration of global variables???

    I'm very sure that the member fn-itemDoubleClicked is being calld as it performs many other operations other than assigning a value to 'var'.
    rgards,
    kavitha

  5. #5
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: declaration of global variables???

    Since you are not getting and Compile time errors ....

    I am sure that you are clearing the var else where
    or you might be using the variable before the function gets called !

    And please avoid using Globals ... Anyone Anywhere can Change it !!!
    It is not a good programming practise. Please go through the links
    http://www.codeguru.com/Cpp/Cpp/cpp_...icle.php/c823/
    http://www.steveheller.com/cppad/Output/function8.html
    We can't solve problems by using the same kind of thinking we used when we created them

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: declaration of global variables???

    Can you show us the part of code where you display the variable content and a kind of explanation how your application works? Because you didn't really provide any info about the subject, just noted the fact that "it doesn't work". Don't expect people to solve your problems if you don't provide any info which could help them.

  7. #7
    Join Date
    Jan 2006
    Posts
    46
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: declaration of global variables???

    If you shoudn't use global variables, how do you pass a variable
    (in this case an int **) from a QWidget to a function which is written
    in mazeform.ui.h?

    In mazeform.ui.h I have the filesave function, which should save the
    values of this int **. It is not in an object, it is just in mazeform.ui.h,
    which is where the Designer wrote it.

    Oh, please, and the other way round too? The fileopen() will need to
    send an int ** to the widget.

    Mariane

    PS I posted here because I started by looking for global variables or
    ways round using them. If I should have started a new post please
    tell me.

Similar Threads

  1. QDevelop - global variables & help
    By impeteperry in forum Qt-based Software
    Replies: 2
    Last Post: 10th June 2011, 00:28
  2. problem with forward declaration
    By MarkoSan in forum General Programming
    Replies: 14
    Last Post: 6th January 2008, 22:45
  3. Qt and global variables
    By Morea in forum Qt Programming
    Replies: 11
    Last Post: 2nd February 2007, 00:42
  4. Global variables
    By Mariane in forum Newbie
    Replies: 14
    Last Post: 10th October 2006, 18:23

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.