Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Connection/Slot question
Forum Updated to NodeBB v4.3 + New Features

Connection/Slot question

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maybnxtseasn
    wrote on last edited by
    #1

    I have the following Class in creation that looks like so

    @class CQueryHandler : public QObject
    {
    Q_OBJECT

    public:
    CQueryHandler(QObject* pParent = 0);
    bool Initialize();
    ~CQueryHandler();

    public:
    void SendQuery(const QString& strQuery);

    protected slots:
    void QueryFinished(QNetworkReply* pNetReply);

    private:
    QNetworkAccessManager* m_pNetworkManager;
    QByteArray m_ByteArray;

    } g_QueryHandler;@

    @
    CQueryHandler::CQueryHandler(QObject* pParent)
    : QObject(pParent), m_pNetworkManager(NULL)
    {

    }

    bool CQueryHandler::Initialize()
    {
    // Initialized Network Manager
    m_pNetworkManager = new QNetworkAccessManager(this);
    if (m_pNetworkManager == NULL) {
    return false;
    }

    // Setup Connections
    connect(m_pNetworkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(QueryFinished(QNetworkReply*)));
    }

    void CQueryHandler::QueryFinished(QNetworkReply* pNetReply)
    {
    // TODO: Error checking

       // Perform Parsing and extra things from returned query
    
       // Extract Data from reply to a QByteArray  Object
        m_ByteArray = pNetReply->readAll();
    

    }@

    This is just a rough outline of what i have. Pretty much i have CRequestHandler...Which will request my webserver for a particular Query and upon completion and retrieval of the information will perform some extra processing and parsing and save the information in my BYTEARRAY member.

    If my program is using the above global object( g_QueryHandler ), and i have a simple dialog with a button the user can click, i understand how to send the QueryRequest as shown below

    @void Dialog::Clicked()
    {
    g_QueryHandler.SendQuery("somequery to send to webserver");
    }@

    But what im unsure of is how to INFORM my Dialog:: that the request has finished and the above Dialog:: object can check the Query information returned from the request inside of g_QueryHandler.m_ByteArray member variable?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      p-himik
      wrote on last edited by
      #2

      Add this to CQueryHandler's definition:
      @signals:
      void queryFinished();
      @

      Add this to Dialog's definition:
      @public slots:
      void queryHandlerFinished();
      @

      Add this to Dialog:Dialog():
      @
      connect( &g_QueryHandler, SIGNAL( queryFinished() ), SLOT( queryHandlerFinished() ) );
      @

      In the implementation of queryHandlerFinished() do whatever you want.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        Don't forget to actually emit that signal too, for example at the end of your CQueryHandler::QueryFinished method:
        @
        emit queryFinished();
        @

        1 Reply Last reply
        0
        • P Offline
          P Offline
          p-himik
          wrote on last edited by
          #4

          Oh, yes, forgot to mention. Thanks.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved