QT中实现libmodbus库的使用

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了QT中实现libmodbus库的使用相关的知识,希望对你有一定的参考价值。

我这样调用可以吗?把库文件加到工程下面,界面两个lineEdit一个发命令,一个接收响应帧。
int rc;
int raw_req_length=0,req_length=0;
QString in,out;
QByteArray ba;
const uint8_t *req=0;
uint8_t *raw_req=0;
ctx=modbus_new_rtu("COM4",19200,'N',8,1);
in=ui->sendlineEdit->text();
ba=in.toLocal8Bit();
raw_req=(unsigned char*)ba.data();
rc=modbus_send_raw_request( ctx,raw_req,raw_req_length);//发送的请求帧
uint8_t *msg=0;
modbus_mapping_t *mb_mapping=0;
rc = modbus_reply(ctx,req,req_length,mb_mapping); //响应帧
out=QString::fromUtf8((const char *)msg);
ui->respondlineEdit->setText(out);
最后运行起来了,输入请求帧了就出问题。求高手帮忙

帮顶了,我现在连最基本的libmodbus 的使用方法都不清楚,也在找资料
楼主,发现了你在QtCN的帖子,说是已经解决了,怎么解决的,如何使用libmodbus编写master端和slave以及如何收发,楼主能不能发个示例代码给我?
邮箱是hello_alan@qq.com
非常感谢!
参考技术A 我现在也在弄这个才刚刚开始,一头雾水,楼主能给我发一份示例代码吗?谢谢了!我的邮箱gxklcy@163.com

如何在 Qt 无框窗口中实现 QSizeGrip?

【中文标题】如何在 Qt 无框窗口中实现 QSizeGrip?【英文标题】:How to implement QSizeGrip in a Qt frameless window? 【发布时间】:2011-08-21 16:33:17 【问题描述】:

如何使用 Qt 无框窗口实现 QSizeGrip?

代码会是什么样子?

【问题讨论】:

【参考方案1】:

您只需在布局内窗口的一角添加一个 QSizeGrip 以使其保持在该角落。

QDialog *dialog = new QDialog(0, Qt::FramelessWindowHint);
QVBoxLayout *layout = new QVBoxLayout(dialog);

// To remove any space between the borders and the QSizeGrip...      
layout->setContentsMargins(QMargins());         
// and between the other widget and the QSizeGrip
layout->setSpacing(0);
layout->addWidget(new QTextEdit(dialog));

// The QSizeGrip position (here Bottom Right Corner) determines its
// orientation too
layout->addWidget(new QSizeGrip(dialog), 0, Qt::AlignBottom | Qt::AlignRight);

dialog->show();

【讨论】:

如果它是一个小部件的孩子呢?当我将它添加到 QHBoxLayout 时,它会将我所有的小部件“推”到左侧,所以我想让它成为一个小部件的子级,它可以位于的“顶部”

以上是关于QT中实现libmodbus库的使用的主要内容,如果未能解决你的问题,请参考以下文章

Arm Qt 实战二:使用libmodbus创建MobusRtu-modbus_new_rtu为NULL的问题

libmodbus 单元 ID 更改

QT 基础Qt中实现树形结构可以使用QTreeWidget类

在 qt 中实现 GUI Shell

如何在 Qt 中实现基于 GStreamer 的视频小部件?

如何在qt中实现代码完成[关闭]