Qt系列——Win10下LCM通讯库在Qt中的使用及问题解决
1. 说明
在windows10下Qt使用Lcm通讯库,以及数据传输测试,运行界面如下:
1)发送端:
2)接收端:
2. 主要代码段
1)发送端
void MainWindow::on_btn_select_clicked()
{
QString path = QFileDialog::getOpenFileName(this, "选择 img", "./", "Image Files(*.jpg *.png *.jpeg)");
if(path.isEmpty())
{
return;
}
QImage scaledimg;
if(!(img.load(path))) //加载图像
{
QMessageBox::information(this,"failed","failed open image !");
return;
}
img=img.convertToFormat(QImage::Format_RGB888);
src_width=img.width();
src_height=img.height();
int scal_width=0;
int scal_height=0;
QString str_width,str_heigth;
QRect originRect = ui->label_image->geometry();
ui->label_image->setGeometry(originRect.x(),originRect.y(),400,300);
int Mul=1;
if(src_width/400>=src_height/300)
{
Mul=src_width/400;
}
else
{
Mul=src_height/300;
}
if(Mul>0)
{
scal_width=src_width/Mul;
scal_height=src_height/Mul;
}
else
{
scal_width=src_width;
scal_height=src_height;
}
scaledimg=img.scaled(scal_width,scal_height,Qt::KeepAspectRatio);
ui->label_text->setText("src image: "+QString("width: ")+str_width.setNum(src_width)+QString(", height: ")+str_heigth.setNum(src_height));
ui->label_image->setPixmap(QPixmap::fromImage(scaledimg));
}
void MainWindow::on_btn_send_clicked()
{
//lcm feed msg
if(!mylcm.good())
{
QMessageBox::information(this,"lcm","lcm is not good!");
return;
}
qint64 timestamp = QDateTime::currentDateTime().toMSecsSinceEpoch();
std::string str_image_name;
str_image_name=ui->lineEdit_image_name->text().toStdString();
std::string str_channel_name;
str_channel_name=ui->lineEdit_channel_name->text().toStdString();
exlcm::test msg;
msg.timestamp=timestamp;
msg.p