如何在Qt中集成paho eclipse库

  • 本文关键字:paho eclipse 集成 Qt qt paho
  • 更新时间 :
  • 英文 :


我想知道是否有办法将 eclipse paho 库与 qt 集成

现在我正在手动包含项目中的所有 c 和 h 文件。 现在导致内存的分割错误

我想知道有没有更好的方法将paho eclipse与qt集成?

Thread 1 "AwsIot" received signal SIGSEGV, Segmentation fault.
memcpy () at ../sysdeps/arm/armv7/multiarch/memcpy_impl.S:608
608 ../sysdeps/arm/armv7/multiarch/memcpy_impl.S: No such file or directory.
(gdb) where
#0  memcpy () at ../sysdeps/arm/armv7/multiarch/memcpy_impl.S:608
#1  0x00409540 in writeMQTTString (pptr=pptr@entry=0x7effc4bc, mqttstring=...) at ../AwsIot/mqtt/MQTTPacket.c:198
#2  0x00409798 in MQTTSerialize_publish (buf=buf@entry=0x48c8d8 "0"217320", buflen=buflen@entry=10340, dup=<optimized out>, qos=0, retained=retained@entry=0 '00', packetid=2468, topicName=..., 
payload=0x50c9c8 "{"hello":"from qt"}", payloadlen=19) at ../AwsIot/mqtt/MQTTSerializePublish.c:78
#3  0x00407f0c in MqttClient::sendMqPub_onEntry (this=0x48c8c0) at ../AwsIot/mqttclient.cpp:244
#4  0x0040a57c in MqttClient::qt_static_metacall (_o=0x48c8c0, _c=<optimized out>, _id=<optimized out>, _a=<optimized out>) at moc_mqttclient.cpp:296
#5  0x7620350e in QMetaObject::activate(QObject*, int, int, void**) () from /usr/lib/libQt5Core.so.5
#6  0x7626fb26 in QAbstractState::entered(QAbstractState::QPrivateSignal) () from /usr/lib/libQt5Core.so.5
#7  0x7626fc60 in ?? () from /usr/lib/libQt5Core.so.5
#8  0x76268a58 in QStateMachinePrivate::enterStates(QEvent*, QList<QAbstractState*> const&, QList<QAbstractState*> const&, QSet<QAbstractState*> const&, QHash<QAbstractState*, QVector<QPropertyAssignment> >&, QList<QAbstractAnimation*> const&) () from /usr/lib/libQt5Core.so.5
#9  0x76269468 in QStateMachinePrivate::microstep(QEvent*, QList<QAbstractTransition*> const&, CalculationCache*) () from /usr/lib/libQt5Core.so.5
#10 0x76269670 in QStateMachinePrivate::_q_process() () from /usr/lib/libQt5Core.so.5
#11 0x76269d88 in QStateMachinePrivate::handleTransitionSignal(QObject*, int, void**) () from /usr/lib/libQt5Core.so.5
#12 0x7626bee2 in ?? () from /usr/lib/libQt5Core.so.5
#13 0x7620357e in QMetaObject::activate(QObject*, int, int, void**) () from /usr/lib/libQt5Core.so.5
#14 0x00407d1a in MqttClient::publishAnyData (this=this@entry=0x48c8c0, topic=..., payload=..., dup=0, packetId=packetId@entry=2468, qos=qos@entry=0, retain=0) at ../AwsIot/mqttclient.cpp:303
#15 0x0040a1d2 in MqttClient::qt_static_metacall (_o=_o@entry=0x48c8c0, _c=_c@entry=QMetaObject::InvokeMetaMethod, _id=_id@entry=41, _a=_a@entry=0x7effca48)
at /opt/poky/2.7.1/sysroots/cortexa7t2hf-neon-vfpv4-poky-linux-gnueabi/usr/include/QtCore/qrefcount.h:60
#16 0x0040aabe in MqttClient::qt_metacall (this=0x48c8c0, _c=QMetaObject::InvokeMetaMethod, _id=41, _a=0x7effca48) at moc_mqttclient.cpp:499
#17 0x767d258c in ?? () from /usr/lib/libQt5Qml.so.5
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

编辑 1:

我在这里附上了我的 .pro 文件

QT += qml quick gui svg xml xmlpatterns network
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
SOURCES += main.cpp 
mqttclient.cpp 
mqtt/MQTTConnectClient.c 
mqtt/MQTTConnectServer.c 
mqtt/MQTTDeserializePublish.c 
mqtt/MQTTFormat.c 
mqtt/MQTTPacket.c 
mqtt/MQTTSerializePublish.c 
mqtt/MQTTSubscribeClient.c 
mqtt/MQTTSubscribeServer.c 
mqtt/MQTTUnsubscribeClient.c 
mqtt/MQTTUnsubscribeServer.c 
statemachine/guardedsignaltransition.cpp 
statemachine/p4statemachine.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += 
mqttclient.h 
mqtt/MQTTConnect.h 
mqtt/MQTTFormat.h 
mqtt/MQTTPacket.h 
mqtt/MQTTPublish.h 
mqtt/MQTTSubscribe.h 
mqtt/MQTTUnsubscribe.h 
mqtt/StackTrace.h 
statemachine/custom_global_var.h 
statemachine/guardedsignaltransition.h 
statemachine/p4statemachine.h 
statemachine/qt_state_machine_macros.h

这是显然导致问题的功能 所以一旦我点击在qml上发布数据

调用转到 MQTT 客户端.cpp

void MqttClient:: sendMqPub_onEntry(){
qDebug()<<"sendMqPub_onEntry";
if (txqueue->isEmpty())
{
txqueue->clear();
emit nothingToPub();
}
else
{
if (gTxPublishInfo != static_cast<_S_MQTT_PUBLISH_INFO *>(nullptr)) {
delete gTxPublishInfo->bap;
delete gTxPublishInfo->tap;
delete gTxPublishInfo;
gTxPublishInfo = (_S_MQTT_PUBLISH_INFO *)nullptr;
}
gTxPublishInfo = txqueue->dequeue();
memset(gMqttTxBuff,0,MQTT_TX_BUFF_LEN_MAX);
int len = MQTTSerialize_publish(gMqttTxBuff, sizeof(gMqttTxBuff), gTxPublishInfo->dup,gTxPublishInfo->qos, gTxPublishInfo->retain, gTxPublishInfo->packetId, gTxPublishInfo->topic, (unsigned char *)gTxPublishInfo->payload, gTxPublishInfo->payloadLen);
m_mqttSkt->write(QByteArray((const char*)gMqttTxBuff,len));
}
}

然后转到MQTTSerializePublish.c

int MQTTSerialize_publish(unsigned char* buf, int buflen, unsigned char dup, int qos, unsigned char retained, unsigned short packetid,
MQTTString topicName, unsigned char* payload, int payloadlen)
{
unsigned char *ptr = buf;
MQTTHeader header = {0};
int rem_len = 0;
int rc = 0;
FUNC_ENTRY;
if (MQTTPacket_len(rem_len = MQTTSerialize_publishLength(qos, topicName, payloadlen)) > buflen)
{
rc = MQTTPACKET_BUFFER_TOO_SHORT;
goto exit;
}
header.bits.type = PUBLISH;
header.bits.dup = dup;
header.bits.qos = qos;
header.bits.retain = retained;
writeChar(&ptr, header.byte); /* write header */
ptr += MQTTPacket_encode(ptr, rem_len); /* write remaining length */;
writeMQTTString(&ptr, topicName);
if (qos > 0)
writeInt(&ptr, packetid);
memcpy(ptr, payload, payloadlen);
ptr += payloadlen;
rc = ptr - buf;
exit:
FUNC_EXIT_RC(rc);
return rc;
}

最终进入MQTTPacket.c并崩溃

void writeMQTTString(unsigned char** pptr, MQTTString mqttstring)
{
if (mqttstring.lenstring.len > 0)
{
writeInt(pptr, mqttstring.lenstring.len);
memcpy(*pptr, mqttstring.lenstring.data, mqttstring.lenstring.len);
*pptr += mqttstring.lenstring.len;
}
else if (mqttstring.cstring)
writeCString(pptr, mqttstring.cstring);
else
writeInt(pptr, 0);
}

我的应用程序没有在 valgrind 上崩溃,但它在 gdb 上崩溃了,这促使我进行调查。 显然长度变量没有初始化。这是根本原因。一旦我将其设置为零。它开始工作,我现在很高兴。

我还发现覆盆子派是一个非常无情的环境。

最新更新