Closed PaguaToP closed 7 years ago
@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.
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();
}
Fixed. I use static build library QAmqpClient
Now QAmqpClient not work with QtService. For connect I use code from tutorials/helloworld/receive:
Please, help me