QDateTime MyClassA::timeTransfer(QString datetime)
{
// "Tue May 31 17:46:55 +0800 2011"
int year,month=1,day,hour,min,sec;
year=datetime.section(" ",5,5).toInt();
QString mon=datetime.section(" ",1,1);
QStringList monthList;
monthList<<"Jan"<<"Feb"<<"Mar"<<"Apr"<<"May"<<"Jun"<<"Jul"<<"Aug"<<"Sep"<<"Oct"<<"Nov"<<"Dec";
month=monthList.indexOf(mon)+1;
day=datetime.section(" ",2,2).toInt();
QString time=datetime.section(" ",3,3);
QStringList timelist=time.split(":");
hour=timelist.at(0).toInt();
min=timelist.at(1).toInt();
sec=timelist.at(2).toInt();
QDate date_=QDate(year,month,day);
QTime time_=QTime(hour,min,sec);
QDateTime datetime_=QDateTime(date_,time_);
return datetime_;
}
我在一个类中定义了这样一个共有函数,其中都是使用了临时变量,而没有类的数据成员。
我在另一个类MyClass的一个槽函数slotFunc()中调用了这个MyClass类的这个时间转换函数:
假如MyClassA *my;
MyClassB::slotFunc()
{
my->timeTransfer("QSTRING1");
}
这样没有问题。然再往其中调用一次
MyClassB::slotFunc()
{
my->timeTransfer("QString1");
my->timeTransfer("QString2)"; //QString2是不同于QString1的另一个时间字符串
}
则提示索引范围出错了:
ASSERT failure in QList<T>::at: "index out of range", file ../../../../Desktop/Qt/4.7.4/mingw/include/QtCore/qlist.h, line 456
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.
QWaitCondition: Destroyed while threads are still waiting
我接触得比较多的是C语言,C++现在是边学边用。
这个问题是由于C++的语法错误码?还是QT内部的机制导致?求解释一下~