串口如何稳定接收数据(转帖)
-
試把
@
connect(
&m_Portconfigview,SIGNAL(signalConfigPort(const SPortsettings *)),&m_Serialportrecevie,SLOT(slotsConfigPort(const SPortsettings *)),Qt::QueuedConnection);
connect(
&m_Portconfigview,SIGNAL(signalConfigPort(const SPortsettings *)),this,SLOT(updatetstatus(const SPortsettings *)));
connect(
&m_Serialportrecevie,SIGNAL(signalThreadToStore( const QByteArray&)),&m_Serialportcachedata,SLOT(slotsSerialportcachedata(const QByteArray&)),Qt::BlockingQueuedConnection);
connect(
&m_Serialportcachedata,SIGNAL(signalToserialportwindow(const QByteArray&)),&m_pSerialPortWindow,SLOT(slotsserialportupdateview(const QByteArray&)),Qt::BlockingQueuedConnection);
@
改成
@
connect(
&m_Portconfigview,SIGNAL(signalConfigPort(const SPortsettings *)),&m_Serialportrecevie,SLOT(slotsConfigPort(const SPortsettings *)));
connect(
&m_Portconfigview,SIGNAL(signalConfigPort(const SPortsettings *)),this,SLOT(updatetstatus(const SPortsettings *)));
connect(
&m_Serialportrecevie,SIGNAL(signalThreadToStore( const QByteArray&)),&m_Serialportcachedata,SLOT(slotsSerialportcachedata(const QByteArray&)));
connect(
&m_Serialportcachedata,SIGNAL(signalToserialportwindow(const QByteArray&)),&m_pSerialPortWindow,SLOT(slotsserialportupdateview(const QByteArray&)));
@ -
Did you test release build?
-
measure time consumed by slotsSerialportcachedata and slotsserialportupdateview via QElapsedTimer
另外你要確保你的PC 沒有問題.你有否在另一台PC試過你的程序?
@
QElapsedTimer timer;
timer.start();
slowOperation1();
qDebug() << "The slow operation took" << timer.nsecsElapsed() << "nanoseconds";
@ -
HI Vincent007
前阵子忙别的去,所以今天才回复你,不好意思按照你说的用以下代码进行测试
timer.start();
pSerialPortQPlainTextEdit.insertPlainText(DatatFormRead);
pSerialPortQPlainTextEdit.moveCursor(QTextCursor::End, QTextCursor::KeepAnchor);
qDebug() << "The slow operation took" << timer.nsecsElapsed() <<"nanoseconds";
下面是测试结果:
The slow operation took 1017500 nanoseconds
The slow operation took 1018310 nanoseconds
The slow operation took 1421502 nanoseconds
The slow operation took 1186476 nanosecondsThe slow operation took 10685984 nanoseconds
The slow operation took 10668154 nanoseconds
The slow operation took 10564419 nanoseconds
The slow operation took 10569686 nanoseconds
The slow operation took 10243486 nanoseconds
The slow operation took 10473245 nanoseconds
The slow operation took 10746766 nanoseconds
The slow operation took 10772700 nanoseconds
The slow operation took 10583059 nanoseconds
The slow operation took 11221681 nanoseconds
The slow operation took 10795798 nanoseconds
The slow operation took 16827051 nanosecondsThe slow operation took 222369451 nanoseconds
The slow operation took 205003460 nanoseconds
The slow operation took 222164411 nanoseconds
The slow operation took 204823949 nanoseconds
The slow operation took 209414655 nanoseconds
The slow operation took 186572559 nanoseconds
The slow operation took 209589304 nanoseconds
The slow operation took 214433676 nanoseconds
The slow operation took 219041401 nanoseconds
说明qt的窗口刷新确实有问题,请指教谢谢。 -
@
#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
_timer.setInterval(10);for(int i = 0; i<1024;i++) { message += "1"; } connect(&_timer,&QTimer::timeout,this,&MainWindow::updateText); _timer.start();
}
MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::updateText()
{
ui->textEdit->append(message);
}
@
I did a simple application and test it. It works fine.
You can try it and adjust parameters. -
I think you should ask this question on http://qt-project.org/forums/viewforum/10/
because more people will answer you. -
I think you should ask this question on http://qt-project.org/forums/viewforum/10/
because more people will answer you.