title: Qt debug error (variable) not accessible
body: <p>I have encountered a runtime error which while debugging list a variable as not accessible. there are other post on this subject but the fixes do not work for me. </p>
  
  <p>I use QtCreator 4.5.1 and Qt lib 5.10 (Mingw32 5.3, MSVC14 x64, MSVC x64)</p>
  
  <p>I have disabled "Load system GDB pretty printers" as suggested in
  <a href="https://stackoverflow.com/questions/21254074/how-to-solve-qt-creators-variable-not-accessible-behavior">disable pretty printers post</a> 
  .</p>
  
  <p><strong>Intent of failing code:</strong></p>
  
  <p><em>In order to communicate between my decoupled QtQuick2 viewmodels I implemented a simple version of the EventAgregator pattern.</em> </p>
  
  <p>the implementation is still missing thread safty and clean up of no longer existing subscribers. however it is not relevant for my error.</p>
  
  <p>break point at error to be thrown and current watch list
  <a href="https://i.stack.imgur.com/EjvAN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EjvAN.png" alt="break point at error to be thrown"></a>
  <a href="https://i.stack.imgur.com/HdMJi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HdMJi.png" alt="watch list at breakpoint"></a></p>
  
  <p>relevant code files:</p>
  
  <p>qspinstartup.h</p>
  
  <pre><code>class QSpinStartup:QObject
  {
  public:
      QSpinStartup();
  
      bool loadQSpin(const QString dir, const QString startView="");
  private:
      void registerQmlGui();
      void registerQmlViewModel();
      QQmlApplicationEngine engine;
  
      //constant viewmodel objects
      CodeEditorTab* codeEditor;
      VerificationTab* verificationEditor;
      QSpinMessageService msgService;
  };
  </code></pre>
  
  <p>qspinstartup.cpp</p>
  
  <pre><code>QSpinStartup::QSpinStartup():QObject()
      ,verificationEditor(new VerificationTab(msgService,this))
      ,codeEditor(new CodeEditorTab(msgService,this))
      //,console(new ConsoleEditor(msgService,this))
  {
  
      registerQmlGui();
      registerQmlViewModel();
      initPointerObjects();
      auto ctx = engine.rootContext();
      qSpinNullPtrCheck(ctx);
      PrintToConsole p("pri");
      msgService.publish&lt;PrintToConsole&gt;(p);
      ctx-&gt;setContextProperty("codeEditorVm",codeEditor);
  }
  
  bool QSpinStartup::loadQSpin(const QString dir,const QString startView)
  {
      QDir ldir(dir);
      QString l = ldir.entryList(QStringList()&lt;&lt;startView,QDir::Files).first();
      qInfo()&lt;&lt;l;
      engine.load(QUrl(l.prepend("qrc:/")));
      bool isReady = engine.rootObjects().count()&gt;0;
      qSpinSafeFail(!isReady,"Qml Application failed to start engine");
  
      return isReady;
  }
  
  void QSpinStartup::registerQmlGui()
  {
      QSpinWorkSpace::Workspace::registerAsQml();
  
  }
  
  void QSpinStartup::registerQmlViewModel()
  {
      VerificationTab::registerAsQml();
      CodeEditorTab::registerAsQml();
      ConsoleEditor::registerAsQml();
  }
  </code></pre>
  
  <p>ieventbase.h</p>
  
  <pre><code>class IEventBase{
  public:
      enum Types{ // &lt;--simple way to give an object a type specifier
          PrintToConsole,
          CurrentDocumentChanged,
          CompilerOptions,
          SpinArgCommand
      };
      IEventBase(Types t):type(t){}
      const Types type;
  };
  </code></pre>
  
  <p>qspinmessageservice.h</p>
  
  <pre><code>template&lt;class T&gt;
  class ISubscriber{
  
  public:
      virtual ~ISubscriber(){}
      virtual void executeSubscribed(T&amp; event)=0;
  };
  class QSpinMessageService: public QObject{
      Q_OBJECT
      typedef QPointer&lt;QObject&gt; subscriber;
      typedef QVector&lt;subscriber&gt; EvAgrList;
      QHash&lt;IEventBase::Types,EvAgrList&gt; subs;
  public:
      QSpinMessageService(QObject* parent=nullptr):QObject(parent)
        ,subs(QHash&lt;IEventBase::Types,EvAgrList&gt;()){}
  
      void subscribe(QObject *obj, IEventBase::Types key){
          if(!subs.contains(key)) // &lt;-- this line cause my error
              subs[key]= EvAgrList();
          EvAgrList&amp; list = subs[key];
          list&lt;&lt;subscriber(obj);
      }
  
      template&lt;typename T&gt;
      void publish(typename T::IEventBase execute){
          EvAgrList lSubs = subs[execute.type];
          for(int i=0; i&lt;lSubs.count();i++){
              subscriber&amp;q = lSubs[i];
              if(q.isNull()){
                  lSubs.removeOne(q);
                  --i;
                  continue;
              }
              ISubscriber&lt;T&gt;* a = dynamic_cast&lt;ISubscriber&lt;T&gt;*&gt;(q.data());
              qDebug()&lt;&lt; q&lt;&lt;a;
  
              //ISubscriber&lt;T&gt;* s = dynamic_cast&lt;ISubscriber&lt;T&gt;*&gt;(q);
              a-&gt;executeSubscribed(static_cast&lt;T&amp;&gt;(execute));
          }
      }
  };
  static QSpinMessageService dummy;
  </code></pre>
  
  <p>verificationtab.cpp   <em>(its a big class so i excluded irrelevant parts)</em></p>
  
  <pre><code>VerificationTab::VerificationTab(QSpinMessageService &amp;service, QObject *parent) :
      QSpinTab(parent,"Verification",QSpinTabType::Verification)
      ,msgService(service)
    ,m_stateProp(new StateSpaceProp(this)),m_stateSpec(new StateSpaceSpec(this))
    ,m_memoryUsage(new MemoryUsage(this)),m_settings(new VerificationSettings(this))
  {
      msgService.subscribe(this,IEventBase::CurrentDocumentChanged); // &lt;-- error call
  //if the line above is commented out the application runs
  }
  </code></pre>
  
  <p><a href="https://github.com/zeplinn/qspin" rel="nofollow noreferrer">Github repository of the full application</a></p>
  
  <p><strong>note:</strong></p>
  
  <p>I Designed the QSpinMessageService in seperate empty project, before adding the files to the main project. the subcribe methods works in that project.</p>
  
  <p>Any idea of how to fix this?</p>