Coder Social home page Coder Social logo

Comments (3)

mbroadst avatar mbroadst commented on September 2, 2024

@PaguaToP you're going to have to provide more context or source code for your issue. I actually originally used this library in a project that used QtService, so I know that it works. It is likely you are having issues with threads or something similar - a code sample would probably resolve this.

from qamqp.

PaguaToP avatar PaguaToP commented on September 2, 2024

My code

Receiver from examples:

class Receiver : public QObject
{
    Q_OBJECT
public:
    Receiver(QObject *parent = 0) : QObject(parent) {
      m_client.setAutoReconnect(true);
    }

public Q_SLOTS:
    void start() {
        connect(&m_client, SIGNAL(connected()), this, SLOT(clientConnected()));
        m_client.connectToHost("myconnectstring");
    }

private Q_SLOTS:
    void clientConnected() {
        QAmqpQueue *queue = m_client.createQueue("hello");
        disconnect(queue, 0, 0, 0); // in case this is a reconnect
        connect(queue, SIGNAL(declared()), this, SLOT(queueDeclared()));
        queue->declare();
    }

    void queueDeclared() {
        QAmqpQueue *queue = qobject_cast<QAmqpQueue*>(sender());
        if (!queue)
            return;

        connect(queue, SIGNAL(messageReceived()), this, SLOT(messageReceived()));
        queue->consume(QAmqpQueue::coNoAck);
        qDebug() << " [*] Waiting for messages. To exit press CTRL+C";
    }

    void messageReceived() {
        QAmqpQueue *queue = qobject_cast<QAmqpQueue*>(sender());
        if (!queue)
            return;

        QAmqpMessage message = queue->dequeue();
        qDebug() << " [x] Received " << message.payload();
    }

private:
    QAmqpClient m_client;
};

My Service class:

class QAService : public QtService<QCoreApplication>
{
public:
    QAService(int argc, char *argv[]) : QtService<QCoreApplication>(argc, argv, "Qa Spider")
    {
        setServiceDescription("Qa Spider");
        setServiceFlags(QtServiceBase::CanBeSuspended);
    }
    ~QAService();

protected:
    void start() { receiver.start(); }
    void pause()  {  }
    void resume() {  }

private:
    Receiver receiver;
};

main.cpp:

int main(int argc, char *argv[])
{
#if !defined(Q_WS_WIN)
    // QtService stores service settings in SystemScope, which normally require root privileges.
    // To allow testing this example as non-root, we change the directory of the SystemScope settings file.
    QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, QDir::tempPath());
#endif

    QAService service(argc, argv);
    return service.exec();
}

from qamqp.

PaguaToP avatar PaguaToP commented on September 2, 2024

Fixed. I use static build library QAmqpClient

from qamqp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.