Results 1 to 2 of 2

Thread: QtService and QLocalSocket

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QtService and QLocalSocket

    I developed a service with QTService with this function

    class DataManageublic QObject
    {
    public:
    DataManage(QObject* parent = 0);
    void ReceiveData(void);
    private:
    QLocalSocket* lpLocalSocket;
    private slots:
    void ReadData(void);
    void displayError(QLocalSocket::LocalSocketError socketError);
    };


    void SettingWidget::SendDataToService(void)
    {
    QLocalSocket *lpClientConnection = lpLocalServer->nextPendingConnection();
    connect(lpClientConnection, SIGNAL(disconnected()),
    lpClientConnection, SLOT(deleteLater()));
    strcpy(s,"eqw\n");
    lpClientConnection->write(s);
    lpClientConnection->flush();
    lpClientConnection->disconnectFromServer();
    }

    void DataManage::ReceiveData(void)
    {
    lpLocalSocket = new QLocalSocket(this);
    connect(lpLocalSocket, SIGNAL(readyRead()), this, SLOT(ReadData()));
    connect(lpLocalSocket, SIGNAL(error(QLocalSocket::LocalSocketError)),
    this, SLOT(displayError(QLocalSocket::LocalSocketError)) );
    lpLocalSocket->abort();
    lpLocalSocket->connectToServer("aaaa");
    }

    void DCSPlusDataManager:rocessCommand(int code)
    {
    logMessage("processCommand", QtServiceBase::Information );
    switch (code)
    {
    case 1:
    DataManage* lpDataManage = new DataManage();
    lpDataManage->ReceiveData();
    break;
    }
    }

    From the main application I send the command that activate processCommand() of the service. It runs.
    Then I send the data to the socket:

    void SettingWidget:n_pushButtonApply_clicked(bool)
    {
    lpLocalServer = new QLocalServer(this);
    if (lpLocalServer->listen("aaaa"))
    {
    connect(lpLocalServer, SIGNAL(newConnection()), this, SLOT(SendDataToService()));
    SC_SendCommand(1);
    }
    }
    //----------------------------------------------------------------------------

    void SettingWidget::SendDataToService(void)
    {
    QLocalSocket *lpClientConnection = lpLocalServer->nextPendingConnection();
    connect(lpClientConnection, SIGNAL(disconnected()),
    lpClientConnection, SLOT(deleteLater()));

    strcpy(s,"eqw\n");
    lpClientConnection->write(s);
    lpClientConnection->flush();
    lpClientConnection->disconnectFromServer();

    }

    The function SendDataToService() is called, although the lpClientConnection->write(s) doesn't call the ReadData() slot connected with readyRead() sognal.
    Where can be the probem?

    Thanks

  2. #2
    Join Date
    Jan 2014
    Posts
    8
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QtService and QLocalSocket

    Hi, how did you defined the SocketOptions of Your QLocalServer? I needed to define theam as follows:

    lpLocalServer->setSocketOptions(QLocalServer::WorldAccessOption) ;

    So that a Server running as Service can be contacted by a User-Program

Similar Threads

  1. QLocalSocket, QThread and Signals
    By StarShaper in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2012, 13:49
  2. emit error for QLocalSocket
    By raj_iv in forum Qt Programming
    Replies: 2
    Last Post: 31st August 2011, 11:14
  3. QLocalSocket Synchronicity
    By matic in forum Qt Programming
    Replies: 0
    Last Post: 25th March 2010, 12:04
  4. Using QLocalServer and QLocalSocket
    By danc81 in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2009, 12:09
  5. IPC with QLocalServer/QLocalSocket
    By ManuMies in forum Qt Programming
    Replies: 1
    Last Post: 11th February 2009, 20:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.