QCopChannel register problem



  • Hello all,

    I'm trying to implement IPC between 2 processes on Debian system using QCop

    Now, I'm looking for several examples on the web, and create follow code:

    Sender
    @bool Helper::sendNotificationToControledApp(QString message)
    {
    bool result = false;
    qDebug() << "Notify method called.";
    #ifndef QT_NO_COP
    if(QCopChannel::isRegistered(COP_CHANNEL_NAME))
    {
    qDebug() << "Channel is registered.";
    }
    else
    {
    qDebug() << "Channel is not registered.";
    }
    result = QCopChannel::send(COP_CHANNEL_NAME, message);
    if (result)
    {
    qDebug() << "Notification sent.";
    }
    else
    {
    qDebug() << "Failed to send the notification.";
    }
    #endif
    return result;
    }@

    Receiver
    @
    #ifndef QT_NO_COP
    this->copChannel = new QCopChannel(COP_CHANNEL_NAME, this); // also tried without "this"
    if(QCopChannel::isRegistered(COP_CHANNEL_NAME))
    {
    qDebug() << "Channel registered.";
    }
    else
    {
    qDebug() << "Channel not registered.";
    }
    connect(this->copChannel, SIGNAL(received(const QString&, const QByteArray&)), this, SLOT(scheduleApplicationRestart(QString,QByteArray)));
    #endif@

    and

    @void MainWindow::scheduleApplicationRestart(const QString &msg, const QByteArray &data)
    {
    this->isRestartScheduled = true;
    qDebug() << "Channel data received:";
    ui->label_2->setText(msg);
    qDebug() << msg;
    qDebug() << data;
    }@

    Now, I get the message from client. He says, the channel is registered.
    In the same time the server says, the channel is not registered.

    I do something wrong. Do anybody have an idea?

    I use Qt 4.7.

    Thank you.


  • Lifetime Qt Champion

    Hi,

    Excepting the confusing messages, is scheduleApplicationRestart getting called ?



  • No, I didn't get any output from this method.


  • Lifetime Qt Champion

    One other thing, are you locked to 4.7 ?



  • Yes, this version is used on the embedded system I'm using.


  • Lifetime Qt Champion

    Are you sure COP_CHANNEL_NAME is the same in both classes ?



  • Yes, I've used copy-paste.

    I have an application, that take some works and watchdog for it.

    First, I'm starting the watchdog. The watchdog starts the application. The QCopChannel instance will be created in client's (application) constructor. After it, the message "Copchannel is registred" coming periodically (Timer).

    In server (watchdog), QCopChannel is not used until the application takes xx % of memory. Then, it should send a message to the application. And here, the server (watchdog) says, the Channel is not registered.

    Is the call-order ok?

    In the first code box: the static send method of QCopChannel returns true (but it doesn't trigger the slot in other application).


  • Lifetime Qt Champion

    Sounds good.

    Did you try with a simple basic implementation ?



  • I implement now 2 application only for COP communication. The same thing.
    It seems for me, the both applications use different "name spaces" of COP (I've no idea about COP architecture).

    I tried also to create an instance in the server application, i. e.

    Server:
    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    this->counter = 0;
    
    this->copChannel = new QCopChannel(COP_CHANNEL_NAME, 0);
    if(QCopChannel::isRegistered(COP_CHANNEL_NAME))
    {
        qDebug() << "Server: Constructor: Cop Channel is registered.";
    }
    else
    {
        qDebug() << "Server: Constructor: Cop Channel is not registered.";
    }
    
    this->timer = new QTimer();
    timer->setInterval(1000);
    connect(this->timer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
    timer->start();
    

    }

    void MainWindow::timerTimeout()
    {
    this->counter ++;
    if(QCopChannel::isRegistered(COP_CHANNEL_NAME))
    {
    if(QCopChannel::send(COP_CHANNEL_NAME, QString::number(this->counter)))
    {
    qDebug() << "Server: Message sent.";
    }
    else
    {
    qDebug() << "Server: Failed to send the message.";
    }
    }
    else
    {
    qDebug() << "Server: Failed to send the message: the channel is not registred.";
    }
    }@

    Client:
    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    QCopChannel channel(COP_CHANNEL_NAME, 0); // also tried to declarate as class member, no changes
    if(QCopChannel::isRegistered(COP_CHANNEL_NAME))
    {
        qDebug() << "Client: Constructor: Cop Channel is registered.";
    }
    else
    {
        qDebug() << "Client: Constructor: Cop Channel is not registered.";
    }
    connect(&channel, SIGNAL(received(const QString &, const QByteArray &)), this, SLOT(timerEvent(const QString &, const QByteArray &)));
    

    }

    void MainWindow::timerEvent(const QString & message, const QByteArray & data)
    {
    qDebug() << "Client: message received: " << message << " -> " << data;
    }@

    In this case, both apps says, the channel is registered, the server sent the message successful - but the client has no data input (or the signal is not triggered... But I don't think so.).


  • Lifetime Qt Champion

    What does COP_CHANNEL_NAME contain ?

    In Client, channel is destroyed at the end for the constructor so it's normal you don't get any messages.



  • @#define COP_CHANNEL_NAME "WatchdogChannel"@

    Yes, it will be destroyed. I've implement this also as a class member, but it doesn't change anything.

    It is strange.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.