title: QT and C++: can't call function outside main() function
body: <p>I would like to know how to call the function <strong>Do_Download()</strong> from the <strong>SocketTest</strong> class outisde the <strong>main()</strong> function.
  The first <strong>cTest.Do_Download()</strong> does work, but when I call the <strong>test()</strong> function, the <strong>csTest.Do_Download()</strong> does not work.</p>
  
  <p>So it looks like I can only acces <strong>SocketTest</strong> from inside the <strong>main()</strong> function, and not from any other function.</p>
  
  <p>Does somebody know how this can be solved?
  Thanks!</p>
  
  <p>main.cpp:</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      QApplication a(argc, argv);
      MainWindow w;
      w.show();
  
      SocketTest cTest;
          cTest.Do_Download();
  
      return a.exec();
  }
  
  
  void test()
  {
      qDebug() &lt;&lt; "test main functie";
  
      SocketTest csTest;
          csTest.Do_Download();
  }
  </code></pre>
  
  <p>SocketTest.h:</p>
  
  <pre><code>#ifndef SOCKETTEST_H
  #define SOCKETTEST_H
  
  #include &lt;QObject&gt;
  #include &lt;QTcpSocket&gt;
  #include &lt;QDebug&gt;
  #include &lt;QHttp&gt;
  #include &lt;QFile&gt;
  #include &lt;QString&gt;
  
  class SocketTest : public QObject
  {
      Q_OBJECT
  public:
      explicit SocketTest(QObject *parent = 0);
  
  
     void Do_Download();
  signals:
  
  public slots:
  
      void stateChanged ( int state );
      void responseHeaderReceived ( const QHttpResponseHeader &amp; resp );
      void requestFinished ( int id, bool error );
  
  private:
      QTcpSocket *socket;
      QHttp *http;
      QHttp *http2;
  
  };
  
  #endif // SOCKETTEST_H
  </code></pre>