How to reach a Qt widget from another class -


i'm implementing tetris. in qt designer drew frame widget. organized qtglass inheriting frame. so, in qt designer looks object frame qtglass class. make figure move within existing limits (walls etc.). i'm trying implement shown below. well, i've come across fact fail reach qtglass object. so, know has method ismovementpossible(), don't know how use it. qtglass instance seems called "frame", if use name, error "unable resolve identifire frame".

could me?

qtglass.h

    #ifndef qtglass_h     #define qtglass_h      #include <qframe>     #include "figure.h"      class qtglass : public qframe {         q_object      public:         bool ismovementpossible();      protected:         figure falcon;     ...     } 

figure.cpp

#include "figure.h" #include "qtglass.h" #include <qtgui> #include <qtgui/qapplication>  void figure::set_coordinates(int direction) {     previous_x = current_x;     previous_y = current_y;     switch (direction) {         case 1:         {//qt::key_left:                         current_x -= 1;             if (frame->ismovementpossible()) {                 break;             }             current_x += 1;             break;         } ... } 

to accessible within figure method frame variable have either global variable or member of figure class (or of superclass).

if need access qtglass instance within figure instance need pass reference (or pointer) it. can either pass figure when constructed (assuming frame outlives figure) or pass parameter method needs it.

for example, if frame outlives figures within like

class qtglass; // forward declare avoid circular header include  class figure { public:     figure( const qtglass& glass ) : frame( glass ) {}      void set_coordinates(int direction) {         // ...         if (frame.ismovementpossible()) {             break;         }         // ...     }      // other methods...  private:     const qtglass& frame;     // other members... }; 

and qtglass constructor do

qtglass::qtglass( qwidget* parent )     : qframe( parent )     , falcon( *this ) { } 

alternatively have dedicated setter method setting frame on figure if setting @ construction time not convenient. member need pointer in case though (although setter still pass reference).


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -