QT知识整理

1、connect函数的SIGNAL可以是按键、定时器、其他对象的信号。如果是其他对象的信号,对象必须要在当前类中实例化。

 

2、Qt数据类型转换

1)int转QString
int a=10;
QString b;
b=QString::number(a)


2)QString 转int
QString a="120";
int b;
b=a.toInt();

 

3)数据类型转换
char* str1 = "abc";

//char* to QString
方法1:QString str2 = QString(QLatin1String(str1));
方法2:QString str2 = QString("%1").arg(str1);

//QString to char*
char* str3 = str2.toLatin1.data();
如果包含中文:char* str3 = str2.toLocal8bit().data();
通过string转:char* str3 = str2.toStdstring().c_str();//返回值为const char*型

string a = str2.toStdstring();//QString to string
QString b = QString::fromstdstring(a);//string to QString

char* c = a.c_str();//string to const char*
string d(c);//char* to string

//int to string
方法1:
int aa=12;
stringstream ss;
ss<string str = ss.str();

方法2:
string str = to_string(aa);

//string to int
方法1:
istringstream is("12");
int n;
n<

方法2:
int n = atoi(str.c_str());

 

3、保留指定位置小数

float a = 3.1415
QString str = QString::number(a, 'f', 2)

 

4、变长数组QVector用法:

QVector intVec;

intVec.append(1);

int num = intVec.data()[i];

int num = intVec.at(i);

intVec.remove(i);//删除某数
intVec.removeAt(i);
intVec.remove(i,count);//从第i个开始,删除后面count个元素

 

5、查找同一页面所有相同类型控件

const QObjectList list = ui->frame_>children();
for(int i=0; i){
    QObject *o = list.at(i);
    if(o->inherits("QCheckBox")){
        QCheckBox *b = qobject_cast(o);
        if(b->isChecked()){
            sn += (b->text()).append("#");
        }
    }else{
        continue;
    }
}

 

 

http://blog.51cto.com/11496263/1875393

https://blog.csdn.net/qq_42345394/article/details/80803092

Qt信号槽 + 函数指针

https://bbs.csdn.net/topics/392292112?page=1

http://www.job592.com/pay/ms/81205.html

https://blog.csdn.net/baidu_32262373/article/details/54969696

http://mobile.51cto.com/symbian-270982.htm

你可能感兴趣的:(QT知识整理)