Results 1 to 15 of 15

Thread: Global variables

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    46
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Global variables

    I know I'm not supposed to use them, but they make life easier...

    Well, no so easy... :

    I started by writting in a file called globalVariables.h:
    Qt Code:
    1. #ifndef GLOBALVARIABLES_H
    2. #define GLOBALVARIABLES_H 0
    3. int ** Log;
    4. #endif
    To copy to clipboard, switch view to plain text mode 

    Then in maze.cpp and in mazeform.ui.h I did #include "globalVariables.h"
    (I tried to add globalVariables.h in maze.pro, then I removed it, it doesn't
    change anything). I get

    g++ -o maze .obj/maze.o .obj/mazebox.o .obj/main.o .obj/lcdrange.o .obj/mazeform.o .obj/qmake_image_collection.o .obj/moc_lcdrange.o .obj/moc_maze.o .obj/moc_mazeform.o -L/usr/share/qt3/lib -L/usr/X11R6/lib -lqt-mt -lXext -lX11 -lm
    .obj/mazeform.o(.bss+0x0): multiple definition of `Log'
    .obj/maze.o(.bss+0x0): first defined here
    collect2: ld returned 1 exit status
    make: *** [maze] Error 1

    BUT when I remove the #include directive from mazeform.ui.h, I get

    mazeform.ui.h: In member function `virtual void MazeForm::fileSave()':
    mazeform.ui.h:72: error: `GLOBALVARIABLES_H' undeclared (first use this
    function)
    mazeform.ui.h:72: error: (Each undeclared identifier is reported only once for
    each function it appears in.)
    mazeform.ui.h:73: error: `Log' undeclared (first use this function)
    make: *** [.obj/mazeform.o] Error 1

    (I was also testing to see if it knew GLOBALVARIABLES_H)

    AND when I remove the #include from maze.cpp I get

    maze.cpp: In member function `void MazeField::intialiseLog()':
    maze.cpp:89: error: `Log' undeclared (first use this function)
    maze.cpp:89: error: (Each undeclared identifier is reported only once for each
    function it appears in.)
    make: *** [.obj/maze.o] Error 1


    Please tell me WHERE I'm supposed to #include "globalVariables.h" so that
    all files have acces to it and it doesn't get included too often (ignoring the
    preprocessing directives?)???.

    Thank you

    Mariane
    Last edited by Mariane; 1st February 2006 at 17:16. Reason: Unwanted smiley caused by Field:: paintEvent

Similar Threads

  1. QDevelop - global variables & help
    By impeteperry in forum Qt-based Software
    Replies: 2
    Last Post: 9th June 2011, 23:28
  2. QDevelop debuggng - viewing class member variables
    By dbrmik in forum Qt-based Software
    Replies: 0
    Last Post: 7th January 2009, 10:40
  3. creating query string from variables
    By locus in forum General Programming
    Replies: 2
    Last Post: 16th April 2007, 08:50
  4. Qt and global variables
    By Morea in forum Qt Programming
    Replies: 11
    Last Post: 1st February 2007, 23:42
  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.