Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QCopChannel register problem
Forum Updated to NodeBB v4.3 + New Features

QCopChannel register problem

Scheduled Pinned Locked Moved Mobile and Embedded
11 Posts 2 Posters 3.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.
  • SavedS Offline
    SavedS Offline
    Saved
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Excepting the confusing messages, is scheduleApplicationRestart getting called ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • SavedS Offline
        SavedS Offline
        Saved
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          One other thing, are you locked to 4.7 ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • SavedS Offline
            SavedS Offline
            Saved
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Are you sure COP_CHANNEL_NAME is the same in both classes ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • SavedS Offline
                SavedS Offline
                Saved
                wrote on last edited by
                #7

                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).

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Sounds good.

                  Did you try with a simple basic implementation ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • SavedS Offline
                    SavedS Offline
                    Saved
                    wrote on last edited by
                    #9

                    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.).

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      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.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • SavedS Offline
                        SavedS Offline
                        Saved
                        wrote on last edited by
                        #11

                        @#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.

                        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