i defined game class globally in main.cpp like this:
Qt Code:
  1. #include "game.h"
  2.  
  3. #include <QApplication>
  4. #include <QTextCodec>
  5.  
  6. Game *game;
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10. QApplication a(argc, argv);
  11.  
  12. srand(time(0));
  13. game = new Game;
  14. game->show();
  15. return a.exec();
  16. }
To copy to clipboard, switch view to plain text mode 

And in the Bars.cpp its initialized like this:
Qt Code:
  1. #include "game.h"
  2.  
  3. extern Game *game;
To copy to clipboard, switch view to plain text mode 

And if it helps here is the game.h file
Qt Code:
  1. #ifndef GAME_H
  2. #define GAME_H
  3. #include "player.h"
  4. #include "button.h"
  5. #include "sea.h"
  6. #include "land.h"
  7. #include "hotbarslots.h"
  8. #include "soundeffects.h"
  9. #include "story.h"
  10. #include "rabbithole.h"
  11. #include "tree.h"
  12. #include "rock.h"
  13. #include "bars.h"
  14.  
  15. #include <QGraphicsView>
  16. #include <QGraphicsScene>
  17. #include <QObject>
  18. #include <QMouseEvent>
  19. #include <QGraphicsSceneMouseEvent>
  20. #include <QGraphicsScene>
  21. #include <QWidget>
  22. #include <QKeyEvent>
  23.  
  24. class Game: public QGraphicsView{
  25. Q_OBJECT
  26. public:
  27. // this class stuff
  28. static QString in_room;
  29. static QString day_or_night;
  30. static int language; // 0~ENG, 1~SLO,
  31. Game(QWidget *parent=NULL);
  32. void languageMenu();
  33. void menu();
  34. void createMap();
  35. void createPlayer();
  36. void createHotbarSlots();
  37. void spawnAnimals();
  38. void spawnTrees();
  39. void spawnRocks();
  40. void drawBars();
  41. void setStopRectCreated(bool t);
  42. bool getStopRectCreated();
  43. int getDesktopHeight();
  44. int getDesktopWidth();
  45. int getViewHeight();
  46. int getViewWidth();
  47. void setViewWidthToDesktop();
  48. void setViewHeightToDesktop();
  49. void setViewWidthToNormal();
  50. void setViewHeightToNormal();
  51. void changeColorOfButton();
  52. QGraphicsRectItem *stopRect;
  53. void wheelEvent(QWheelEvent *event);
  54. // dark screen stuff
  55. QGraphicsRectItem *darkScreen;
  56. QTimer *darkScreenTimer;
  57. void deleteDarkScreen();
  58. // other class stuff
  59. RabbitHole *rabbitHole;
  60. Story *story;
  61. Player *player;
  62. Land *land;
  63. Sea *sea;
  64. HotbarSlots *hotbarSlots;
  65. SoundEffects *soundEffects;
  66. Tree *tree[3];
  67. Rock *rock[3];
  68. Bars *bars;
  69. // static stuff
  70. private:
  71. // dark screen stuff
  72. double darking_opacity;
  73. bool dark_screen_on;
  74. // this class stuff
  75. int curr_pos_in_menu;
  76. bool stop_rect_created;
  77. int desktop_height;
  78. int desktop_width;
  79. int current_height;
  80. int current_width;
  81. int starting_width;
  82. int starting_height;
  83. public slots:
  84. void setLanguageToSlovenian();
  85. void setLanguageToEnglish();
  86. void startStory();
  87. void start();
  88. // dark screen stuff
  89. void screenGoesDark();
  90. void screenComesFromDark();
  91. };
  92.  
  93. #endif // GAME_H
To copy to clipboard, switch view to plain text mode