void MainWindow:: loadtime1() //读
{/*//int i=0;
vector<int> itime;
int c;
int g=0;
int h=0;
int nn=0;
int ca[65535]={0};
vector<string> itime3;
// char* c1;
// fp1=fopen("./name.dat","r");
string c2;//temp用来将所有的内容存入,用来存储“12345678910”的
ifstream fp( "./time.dat" );
// cout << ch;
// fin.close();
// ifstream fp("./time.dat", ios::in);
// string str;
// getline(fp, c2);
// itime3=c2;
// char* strc;
// strc=(char*)itime3.c_str();
// char * split = ":";
// char * p;
// p = strtok (strc,split);
// while(p!=NULL) {
// // printf ("%s\n",p);
// ca[h++]=atoi(p);
// p = strtok(NULL,split);
// }
// c=ca[0]*3600+ca[1]*60+ca[2];
// itime.push_back(c);
// cout << endl;
// while (getline(fp, c2))//按行读文件
while( getline(fp,c2) )
{
itime3.push_back(c2);
printf("%s\n", itime3[g].c_str());
char* strc;
strc=(char*)itime3[g++].c_str();
char * split = ":";
char * p;
p = strtok (strc,split);
while(p!=NULL) {
// printf ("%s\n",p);
ca[h++]=atoi(p);
p = strtok(NULL,split);
}
h=0;
c=ca[0]*3600+ca[1]*60+ca[2];
itime.push_back(c);
printf("%d\n",itime[nn++]);
// cout<<itime3[1]<<endl;
}
fp.close( );*/
//int i=0;
vector<int> itime;
int c;
int g=0;
int h=0;
int nn=0;
int ca[65535]={0};
vector<string> itime3;
// char* c1;
// fp1=fopen("./name.dat","r");
string c2;//temp用来将所有的内容存入,用来存储“12345678910”的
ifstream fp( "./time.dat" );
// cout << ch;
// fin.close();
// ifstream fp("./time.dat", ios::in);
// string str;
// getline(fp, c2);
// itime3=c2;
// char* strc;
// strc=(char*)itime3.c_str();
// char * split = ":";
// char * p;
// p = strtok (strc,split);
// while(p!=NULL) {
// // printf ("%s\n",p);
// ca[h++]=atoi(p);
// p = strtok(NULL,split);
// }
// c=ca[0]*3600+ca[1]*60+ca[2];
// itime.push_back(c);
// cout << endl;
// while (getline(fp, c2))//按行读文件
while( getline(fp,c2) )
{
itime3.push_back(c2);
printf("%s\n", itime3[g].c_str());
char* strc;
strc=(char*)itime3[g++].c_str();
char * split = ":";
char * p;
p = strtok (strc,split);
while(p!=NULL) {
// printf ("%s\n",p);
ca[h++]=atoi(p);
p = strtok(NULL,split);
}
h=0;
c=ca[0]*3600+ca[1]*60+ca[2];
itime.push_back(c);
printf("%d\n",itime[nn++]);
// cout<<itime3[1]<<endl;
}
fp.close( );
// fp=fopen("./time.dat","r");
// fscanf(fp,"%s", strc);
// while(!feof(fp))
// {
// itime.push_back(c);
// fscanf(fp,"%d",&c);
// i++;
// }
// fclose(fp); //这儿获取的数字最准确 获取时间列表的时间 自己加 Qtime类的时间
//// // printf("%d\n",itime.size()); //调试
//// for(int i=0;i<itime.size();i++)
//// printf("%d\n", itime[i]);
// QTime n(0, 0, 0); // n = 00:00:00
//QTime t1;
////MainWindow w1;
// for(int i=0;i<itime.size();i++)
// {
// t1 = n.addSecs(itime[i]);
// timeClicked(t1);
// }
// //qDebug() << t.toString("hh:mm:ss"); //t = 00:01:10
// char* itime2[65535]={"0"};
vector<char*> itime1;
vector<string> itime2;
// char* c1;
// fp1=fopen("./name.dat","r");
string c1;//temp用来将所有的内容存入,用来存储“12345678910”的
// ifstream fp1("./name.dat", ios::in); //原来的
ifstream fp1("./time.dat", ios::in);//后来的
// string str;
string str2,str3;
getline(fp1, c1);
istringstream is(c1);
is>>str2>>str3;
c1=str3;
str3="";
itime2.push_back(c1);
while (getline(fp1, c1))//按行读文件
{
istringstream is(c1);
is>>str2>>str3;
c1=str3;
str3="";
itime2.push_back(c1);
cout<<itime2[1]<<endl;
}
fp1.close( );
// //fscanf(fp1,"%s\r\n",c1);
// // fgets(c1,22,fp1);
//// getline(fp1, c1);//按行读文件
// //cout << str << endl;//这
// string str;
// str=c1;
// itime1.push_back(c1);
// itime2.push_back(str);
// // itime2[i++]=c1;
// while(!feof(fp1))
// // for(int j=0;j<i;j++)
// {
// // itime2[i++]=c1;
// itime1.push_back(c1);
// itime2.push_back(str);
// // printf("%s\n",itime1[1]);
//// cout<<itime2[1];
// getline(fp1, c1);//按行读文件
// // fscanf(fp1,"%s\r\n",c1);
// // fgets(c1,22,fp1);
// // printf("%s\n",itime1[2]);
// }
//fclose(fp1); //这儿获取的数字最准确 获取时间列表的时间 自己加 Qtime类的时间
QTime n(0, 0, 0); // n = 00:00:00
QTime t1;
//MainWindow w1;
QString t2;
for(int j=0;j<itime.size();j++)
{ //printf("%s\n",itime1[i]);
printf("%s\n",itime2[j].c_str());
t1 = n.addSecs(itime[j]);
QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8")); //保证写出的文字显示不乱码 编码格式的转化
//用GBK编的码就用gbk来解码白框里显示名字
t2= QString(tr(itime2[j].c_str())); //char 转
QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK")); //弹出的对话框中显示的文字
timeClicked(t1,t2);
}
}
void MainWindow::addClicked()//写
{
timeList<<ui->timeEdit->time();//输入时间框获取时间的
contentList<<(ui->textEdit->toPlainText().isNull() ? " ":ui->textEdit->toPlainText());
if (ui->textEdit->toPlainText().isEmpty())
{
QMessageBox::warning(this, tr("设置时间"),tr("请输入备忘内容"));
return;
}
ui->listWidget->addItem(timeList.last().toString("hh:mm:ss")+" "+contentList.last());
QTimer *tempTimer=new QTimer(this);
timerList<<(tempTimer);
if(((timeList.last().hour()*3600+timeList.last().minute()*60+timeList.last().second())-(QTime::currentTime().hour()*3600+QTime::currentTime().minute()*60+QTime::currentTime().second()))>0)
{
// FILE * fp=fopen("./time.dat","a");
// fprintf(fp,"%d:%d:%d\n",timeList.last().hour(),timeList.last().minute(),timeList.last().second());
// fclose(fp); //这儿获取的数字最准确 获取时间列表的时间 自己加 Qtime类的时间
//把Qtime时间转换为妙
// if(flag==1)
// {
//// fp=fopen("./time.dat","a");
//// fprintf(fp,"%d\n",timeList.last().hour()*3600+timeList.last().minute()*60+timeList.last().second());
//// fclose(fp); //这儿获取的数字最准确 获取时间列表的时间 自己加 Qtime类的时间
// fp=fopen("./time.dat","a");
// fprintf(fp,"%d:%d:%d\n",timeList.last().hour(),timeList.last().minute(),timeList.last().second());
// fclose(fp); //这儿获取的数字最准确 获取时间列表的时间 自己加 Qtime类的时间
// }
qstr=ui->textEdit->toPlainText();
char* ch;
// QByteArray ba = contact.toLatin1();
// QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));
// QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8"));
QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf-8"));
ch = qstr.toLocal8Bit().data();//字符串转化
// if(flag==1)
// {
// fp1=fopen("./name.dat","a");
// fprintf(fp1,"%s\n",ch);
// fclose(fp1); //这儿获取的数字最准确 获取时间列表的时间 自己加 应该写在保存之后的内容里
// }
if(flag==1)
{
fp=fopen("./time.dat","a");
fprintf(fp,"%d:%d:%d ",timeList.last().hour(),timeList.last().minute(),timeList.last().second());
fprintf(fp,"%s\n",ch);
fclose(fp); //这儿获取的数字最准确 获取时间列表的时间 自己加 Qtime类的时间
}
cstr.push_back((string)ch); //c语言字符串转c++
QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));
//QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8")); //保证写出的文字显示不乱码 编码格式的转化
timerList.last()->start(((timeList.last().hour()*3600+timeList.last().minute()*60+timeList.last().second())-(QTime::currentTime().hour()*3600+QTime::currentTime().minute()*60+QTime::currentTime().second()))*1000);
timerList.last()->setSingleShot(true);
connect(timerList.last(),SIGNAL(timeout()),this,SLOT(showMessage()));
//int i=ui->listWidget->currentRow();
}
}
void MainWindow::timeClicked(QTime T,QString T2) //读
{
// timeList<<ui->timeEdit->time();//输入时间框获取时间的
timeList<<T;
contentList<<(T2.isNull() ? " ":T2);
ui->listWidget->addItem(timeList.last().toString("hh:mm:ss")+" "+contentList.last());
QTimer *tempTimer=new QTimer(this);
timerList<<(tempTimer);
if(((timeList.last().hour()*3600+timeList.last().minute()*60+timeList.last().second())-(QTime::currentTime().hour()*3600+QTime::currentTime().minute()*60+QTime::currentTime().second()))>0)
{
// FILE * fp=fopen("./time.dat","a");
// fprintf(fp,"%d:%d:%d\n",timeList.last().hour(),timeList.last().minute(),timeList.last().second());
// fclose(fp); //这儿获取的数字最准确 获取时间列表的时间 自己加 Qtime类的时间
//把Qtime时间转换为妙
// fp=fopen("./time.dat","a");
// fprintf(fp,"%d\n",timeList.last().hour()*3600+timeList.last().minute()*60+timeList.last().second());
// fclose(fp); //这儿获取的数字最准确 获取时间列表的时间 自己加 Qtime类的时间
qstr=T2;
char* ch;
// QByteArray ba = contact.toLatin1();
// QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));
// QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8"));
QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf-8"));
ch = qstr.toLocal8Bit().data();//字符串转化
// FILE * fp1=fopen("./name.dat","a");
// fprintf(fp1,"%s\n",ch);
// fclose(fp1); //这儿获取的数字最准确 获取时间列表的时间 自己加 应该写在保存之后的内容里
cstr.push_back((string)ch); //c语言字符串转c++
QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK"));
//QTextCodec::setCodecForTr(QTextCodec::codecForName("utf-8")); //保证写出的文字显示不乱码 编码格式的转化
timerList.last()->start(((timeList.last().hour()*3600+timeList.last().minute()*60+timeList.last().second())-(QTime::currentTime().hour()*3600+QTime::currentTime().minute()*60+QTime::currentTime().second()))*1000);
timerList.last()->setSingleShot(true);
connect(timerList.last(),SIGNAL(timeout()),this,SLOT(showMessage()));
//int i=ui->listWidget->currentRow();
}
}