设为首页 加入收藏

TOP

让串口调试助手像命令行一样(二)
2019-01-10 20:09:26 】 浏览:531
Tags:串口 调试 助手 命令 一样
eft,QTextCursor::KeepAnchor,history[historyNum].length());
12 } 13 tc.removeSelectedText(); 14 } 15 if(historyNum == 0) 16 historyNum = history.size(); 17 18 ui->tEdit_shell->insertPlainText(history[historyNum-1]); //插入上一个输入的历史记录 19 qout<<history[historyNum-1]<<"history size "<< history.length(); 20 historyNum--; 21 qout<<"使用上一个记录"<<endl; 22 23 return true; View Code

 

如果按下了enter 把最后一行的文本获取到,用串口发送出去,将发出去的字符写入一个数组,记录下来以便提供历史记录

 1 if(k->key() == Qt::Key_Return || k->key() == Qt::Key_Enter)
 2             {
 3                 txtcur.movePosition(QTextCursor::End,QTextCursor::MoveAnchor);
 4                 txtcur.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
 5                 txtcur.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
 6                 QString msg = txtcur.selectedText();
 7                 history.append(msg);
 8                 sendText(msg);
 9 
10                 historyNum = history.size();
11                 ui->tEdit_shell->append("");
12                 return true;
View Code

 

如果按下了方向上键,不上移光标,然后判断是不是最后一个的输入记录,如果是,直接在光标位置处插入上一次发送的文本,如果不是最后一个历史记录,删除当前历史的历史记录语句,插入更加前面一条历史语句.

如果删除时发现已经删除到最后一行的开始,则删除无效.

1 if (static_cast<QKeyEvent *>(event)->key() == Qt::Key_Backspace) {
2                 QTextCursor tc = ui->tEdit_shell->textCursor();
3                 int oldposition = tc.position();
4                 tc.movePosition(QTextCursor::StartOfLine);
5                 if((tc.blockNumber()+1) == maxline && oldposition == tc.position())
6                 {
7                     return true;
8                 }
View Code

 

恩,逻辑上还是比较简单的.每个人都可以做到.

然而,为了能用上好(装)用(逼)的 shell 串口,我们就要去移植一个rt-thread系统吗? NO NO NO.小编也想到这个问题,于是乎,自己编写了一个.c.h 文件,只需一个声明,输入字符串进入执行函数,就会自动调用你想要调用的函数.具体请期待明日更新哦.

 

RTOS [1]    Real Time  Operating System  实时操作系统,. 名称是根据操作系统的工作特性而言的,实时是指物理进程的真实时间.  摘自百度百科 [RTOS]    且RTOS多为抢占式操作系统.

 为了能够更好的交流,小编悄摸的申请了一个公众号: 奔跑的程序猿 ,感兴趣的可以关注一波. 

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇cf1102F. Elongated Matrix(状压d.. 下一篇素数判定

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目