记录一些写代码时的经验,小小的经验,就从今天开始吧。
2013-08-06
std::string 有一个成员函数-- size_type find_first_of(const char* cstr, size_type index = 0);
用法是查找在源字符串中第一个与cstr中的某个字符匹配的字符,返回它的位置。搜索从index开始,如果没找到就返回string::npos.
这个是要好好理解的,举个例子吧。
......................................................................
std::string src = "what is going on ?";
std::string::size_type pos = src.find_first_of("xs", 1); //pos = 6
..................................................................................
经过试验, pos = 6, 也就是说,字符串 “xs” 在src中的字符's' 第一次在src中出现的位置为6,起始索引为0.实际是第7个字符。
这个函数一般用在查单个字符时比较好,若要查找子串的话,还是使用find(const char* str, size_type idx)。
2013-08-07 --从std::string 转到 QString,中文。
std::string str = "汉语";
QString qstr = QString::fromLocal8Bit(str.c_str());
前提是:
QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030"));
2013-08--08 QTableWidget 初始化
void WeatherUI::initTableWidget()
{
m_tableWidget = new QTableWidget(100, 5, this); //第一个参数为行娄,第二个参数为列数
m_tableWidget->resize(550, 300);
QStringList horizontalHeader;
horizontalHeader <<QObject::tr("气温")
<< QObject::tr("湿度")
<< QObject::tr("风向")
<<QObject::tr("风力")
<<QObject::tr("时间");
m_tableWidget->setHorizontalHeaderLabels(horizontalHeader);
m_tableWidget->verticalHeader()->setVisible(false); //取消显示垂直表头
}
2013-08-14 QTimer
1. #include <QTimer>
在头文件中定义 : QTimer m_Timer;\
2.设置时间间隔
m_Timer.setInterval(100); //响应时间为100毫秒
响应时会发出timeout()信号
3.启动
m_timer.start();
4. 定义一个槽函数
public slots:
void timeProc( ) ;
5. 关联信号和槽函数
connect() ;