QT学习
1、在QT的.ui文件中如果想修改界面的实现函数:
1)点击.ui进入界面
2)右键“Send”按钮,点击 跳转到“槽”
3)点击 “OK”,跳转到点击Send按钮时,后端处理的函数
2、在QT中实现定时发送(使用Qt框架中的QTimer
类)
1)首先,需要在类中声明两个QTimer
对象
1 // NCStrategyMainWin.h 或 相应的头文件中 2 3 #include <QTimer> 4 5 class 类名 : public 继承的类名 { 6 // ... 省略其他成员 ... 7 8 QTimer *timer1; // 用于第一个函数的定时器 9 QTimer *timer2; // 用于第二个函数的定时器 10 11 public: 12 // ... 省略其他成员 ... 13 14 void setupTimers(); // 设置定时器的方法 15 };
2)然后,在类构造函数中初始化这两个定时器,并设置它们的超时时间(10毫秒)和连接相应的槽函数
1 // src.cpp 2 3 类名::类名(其他类名 *parent) 4 : 其他类名(parent), timer1(new QTimer(this)), timer2(new QTimer(this)) 5 { 6 // ... 省略其他初始化代码 ... 7 8 setupTimers(); // 调用设置定时器的方法 9 } 10 11 void 类名::setupTimers() 12 { 13 // 设置定时器1 14 connect(timer1, &QTimer::timeout, [this]() { 15 on_ServerCMDSendButton_clicked(); 16 }); 17 timer1->start(10); // 10ms定时 18 19 // 设置定时器2 20 connect(timer2, &QTimer::timeout, [this]() { 21 on_ServerCMDSendButton_2_clicked(); 22 }); 23 timer2->start(10); // 10ms定时 24 }
3)最后,在on_ServerCMDSendButton_clicked()、on_ServerCMDSendButton_2_clicked两个函数里去写要定时发送的命令即可
2、在QT的图形化界面修改:
1)在左侧导航栏托出一个widget(布局),右面为widget的参数(可调整):
2)在左侧导航栏,搜索label和line edit,并将其拖入到widegt中
3)点击上面的“打破布局”(右侧第二个),再点击水平布局(左五)或垂直布局(左六)可重新将widegt布局:
4)选中widget,在下面filter中输入stretch,可以对widget中的label和line edit的比例进行修改: