当前位置:网站首页>Qdoublevalidator does not take effect solution
Qdoublevalidator does not take effect solution
2022-07-27 09:00:00 【Cotoneaster in the grass】
problem :
Use QIntValidator normal , Replace with QDoubleValidator It will not take effect after , Look at what is said on the Internet to increase this line :setNotation(QDoubleValidator::StandardNotation);
It doesn't seem to work , I had to write one myself , At present, the test feels OK .
terms of settlement :
heavy load QDoubleValidator.
class MyDoublevalidator : public QDoubleValidator
{
Q_OBJECT
public:
MyDoublevalidator(QObject *parent = nullptr);
QValidator::State validate(QString &str, int &i) const;
};
MyDoublevalidator::MyDoublevalidator(QObject *parent)
{
}
QValidator::State MyDoublevalidator::validate(QString &str,int &i) const
{
qDebug() << "validate in: str" << str;
if(str == "-" || str == ""){
return Intermediate;
}
bool ok;
double number = str.toDouble(&ok);
if(!ok){
return Invalid;
}
// Judge the decimal point
int dotPos = str.indexOf('.');
if( (dotPos != -1) && (str.length()-dotPos - 1 > decimals()) ){
return Invalid;
}
// Distinguish between negative and positive numbers
if(number >= 0)
{
if(number < bottom()){
return Intermediate;
}
if(number > top()){
return Invalid;
}
}
else
{
// negative
if(number < bottom()){
return Invalid;
}
if(number > top()){
return Intermediate;
}
}
return Acceptable;
}
边栏推荐
- Storage and computing engine
- New year's goals! The code is more standardized!
- Hangzhou E-Commerce Research Institute released an explanation of the new term "digital existence"
- 3311. 最长算术
- CUDA programming-05: flows and events
- "Weilai Cup" 2022 Niuke summer multi school training camp 1
- Some practical, commonly used and increasingly efficient kubernetes aliases
- PyTorch自定义CUDA算子教程与运行时间分析
- 新年小目标!代码更规范!
- Include error in vs Code (new header file)
猜你喜欢

NIO示例
![[interprocess communication IPC] - semaphore learning](/img/47/b76c329e748726097219abce28fce8.png)
[interprocess communication IPC] - semaphore learning

Explain cache consistency and memory barrier

View 的滑动冲突

Pyqt5 rapid development and practice 4.1 qmainwindow

【Flutter -- GetX】准备篇

【微服务~Sentinel】Sentinel之dashboard控制面板

PyTorch自定义CUDA算子教程与运行时间分析

8 kinds of visual transformer finishing (Part 1)

4279. Cartesian tree
随机推荐
D3.v3.js data visualization -- pictures and tips of force oriented diagram
String type and bitmap of redis
How to deploy yolov6 with tensorrt
Huawei machine test question: Martian computing JS
微信安装包从0.5M暴涨到260M,为什么我们的程序越来越大?
New year's goals! The code is more standardized!
2036: [Blue Bridge Cup 2022 preliminary] statistical submatrix (two-dimensional prefix sum, one-dimensional prefix sum)
Built in method of tensorflow model training and evaluation
Software testing function testing a full set of common interview questions [function testing - zero foundation] essential 4-1
JS检测客户端软件是否安装
Interface test tool -postman usage details
Sliding conflict of view
PVT's spatial reduction attention (SRA)
Is online account opening safe? Want to know how securities companies get preferential accounts?
4276. 擅长C
Full Permutation (depth first, permutation tree)
Mangodb简单使用
The wechat installation package has soared from 0.5m to 260m. Why are our programs getting bigger and bigger?
3428. 放苹果
[I2C reading mpu6050 of Renesas ra6m4 development board]