记录我学习Qt中遇到的各种功能函数的用法
1、QLineEdit读取格式
lineedit->text().toAscii().toULong(&ok,16);
无符号长整形十六进制格式读取读取 按ASCII形式读出
2、QLineEdit限制输入
QRegExp regExp("^[A-Za-z0-9]+$"); //这里的意思是可以输入包含大小写字母,阿拉伯数字
lineEdit->setValidator(new QRegExpValidator(regExp, this));QLineEdit限制输入为[A-Z]、[a-z]、[0-9]
3、QString转str str 转QString
string ch1= ui->lineEdit_in_1->text().toStdString();
QString qt_str;
qt_str= QString::fromStdString(str);
4、QLineEdit 编辑触发槽
connect(lineEdit,SIGNAL(selectionChanged()),this,SLOT(a()));
当lineEdit被选中编辑时 触发槽
5、Qt的定时器及其触发
class SleeperThread : public QThread
{
public:
static void msleep(unsigned long msecs)
{
QThread::msleep(msecs);
}
};这里是重写时间单位 这里是ms
QTimer *imageTime = new QTimer(this);
connect(imageTime,SIGNAL(timeout()),this,SLOT(Image_Time()));
imageTime->start(5000);
star为开始计时 5000 即为5000个时间单位 timeout即为时间溢出信号 触发槽函数ImageTime()
6、消息框的弹出与定位
MyMessageBox *MymsgBox;
MymsgBox = new MyMessageBox;
MymsgBox->setWindowTitle("警告");
MymsgBox->setText("两次新密码输入不一致");
MymsgBox->move(this->x()+140,this->y()+100);
MymsgBox->show();
这里是对消息框进行编辑 this->x() this->y()分别为现在的主窗口位置 这样就对消息进行了定位
这个函数是我对消息框重写后进行的编辑
Qt库中 自带有几类消息框
Question 询问
Information 提示
Warning 警告
Critical 错误
用时QMessageBox::question(this,"Question",tr(""),QMessgeBox::Ok);这样调用就可以了
970



被折叠的 条评论
为什么被折叠?



