c++ - How to compare time ranges in text file with time ranges that entered by user in qt? -


i have text file follows:

05:59:57 - [0x1010001]05:59:57 - (2576) writing non-volatile memory done 06:00:00 - [0x1010001]06:00:00 - (23371)  t_check_buddy !!!   06:00:00 - dma:310127952,01,req:brdtim 82 07 83 29 05 0f 04 12 06 00  06:00:00 -  06:00:00 - evmtbl............ 06:00:00 - maintenancing & filling vboxtbl...done 06:00:01 - dma:310128070,01,ind:ktsper 96 10 85 fc 00 28 58  06:00:01 - dma:310128071,01,req:ktsidk 82 10 85 fc 81 00 47 02  06:00:01 - dma:310128091,01,ind:ktsper 96 10 86 fc 00 28 58  06:00:01 - dma:310128091,01,req:ktsidk 82 10 86 fc 81 00 47 02  06:00:02 - sip:310129384, req:     kinfo     to:1800 to-host:192.168.178.230 ktext: 02 78 0e 06:00:30 - [0x1010001]06:00:30 - (23371)  t_check_buddy !!!   06:00:32 - sip:310159385, req:     kinfo     to:1800 to-host:192.168.178.230 ktext: 02 78 0e 06:00:46 - ipt:310173571,255,ind: config 87 03 4c 43 4e 

the code follows:

#include "mainwindow.h" #include "ui_mainwindow.h" #include <fstream> #include <iostream> #include <string> #include <sstream> #include<qfile> #include<qtextstream> #include<qstringlist> #include<qdebug> #include<qmessagebox>  using namespace std;  mainwindow::mainwindow(qwidget *parent) : qmainwindow(parent), ui(new ui::mainwindow) {    ui->setupui(this); }  mainwindow::~mainwindow() {    delete ui; } 

i performed button , lineedits in form.after, splitted time ranges hh:mm:ss format.because have error checking on time ranges.

void mainwindow::on_pushbutton_3_clicked() {    qstring output;    qstring line;    qstringlist splitted;    qstring times;     int sayac1=0,sayac2=0;    bool control1=false;    bool control2=false;      qstring firsttime=ui->lineedit->text();  //first time range entered     user.    qstringlist list1=firsttime.split(":");  //girilen time split edildi.     if (list1.size() < 3)      qmessagebox::warning(this,"list","alanlar boŞ birakilamaz!");     qstring hour1=list1[0];    hour1.toint();     qstring minute1=list1[1];    minute1.toint();     qstring second1=list1[2];    second1.toint();      qstring secondtime=ui->lineedit_2->text();  //second time range     entered user.     qstringlist list2=secondtime.split(":");    //girilen aralık split     edildi.     if(list2.size() < 3)      qmessagebox::warning(this,"list","alanlar boŞ birakilamaz!");     qstring hour2=list2[0];   hour2.toint();    qstring minute2=list2[1];   minute2.toint();    qstring second2=list2[2];   second2.toint(); 

i read text file , splitted file.i have need compare time ranges in text file time ranges entered user.

    qfile file("c:\\kaynak\\naile.txt");         if(file.open(qiodevice::readonly | qiodevice::text)){             qtextstream in(&file);             while(!in.atend())            {                 line = in.readline()+"\n";                output.append(line);                  if(line.contains(" - ")){                    splitted=line.split(" - ");                    times=times+" "+splitted[0];                }                 if(splitted[0]!=firsttime && control1==false){                   sayac1 = sayac1+1;                }                else                   control1=true;                  if(splitted[0]!=secondtime && control2==false){                   sayac2++;                }                else                   control2=true;  } 

in following code,i did error checking mentioned above.and,i tried display records @ specified time intervals.but when run code,nothing seems in textbrowser created display records.i don't understand why happening.also,no error occurs.for example,user entered 05:59:57 first lineedit , 06:00:46 second lineedit.then user clicked button display records @ time intervals.i want display records 05:59:57 06:00:46.but,there no records in textbrowser.nothing seems.how can solve problem?

      if(hour1<=hour2){          int i;         qstring list;         qstring newline=splitted[0]+" - "+splitted[1];         list.append(newline);          if(times.contains(firsttime) && times.contains(secondtime)){             for(i=sayac1+1;i<=sayac2+1;i++){                 ui->textbrowser_3->settext(list.at(i));            }         }          else            qmessagebox::warning(this,"list","gİrdİĞİnİz zaman araliklari             eŞleŞmİyor!");         }           if(hour1>hour2)            qmessagebox::warning(this,"list","İkİncİ saat bİrİncİden bÜyÜk             olamaz!");               file.close();           // return output;    } } 

to compare times must use qtime class, class provides implements time comparison operators. along advisable use qtimeedit provides suitable widget these parameters recommend change them instead of using qlineedit.

an appropriate format has established, following done:

#define format  "hh:mm:ss"  mainwindow::mainwindow(qwidget *parent) :     qmainwindow(parent),     ui(new ui::mainwindow) {     ui->setupui(this);     ui->fromtimeedit->setdisplayformat(format);     ui->totimeedit->setdisplayformat(format);     ui->totimeedit->settime(qtime::fromstring("23:59:59", format)); } 

then in slot called when press button task of filtering times, checks if limits adequate. after read file , first 8 characters convert in time , if valid , between times change flag, if instead not valid leave was, of above implemented in following code:

void mainwindow::on_pushbutton_clicked() {     const qtime =  ui->fromtimeedit->time();     const qtime = ui->totimeedit->time();      bool copylog = false;     if(from <= to){         qfile file("/path/of/kaynak.log");         ui->textedit->clear();         if(file.open(qiodevice::readonly | qiodevice::text)){             qtextstream in(&file);             while(!in.atend()){                 const qstring line = in.readline();                 const qtime timelog = qtime::fromstring(line.left(8), format);                 if(timelog.isvalid()){                     copylog = timelog >= && timelog <= to;                 }                 if(copylog){                     ui->textedit->append(line);                     qapplication::processevents();                 }             }         }     } } 

the following image shows result:

enter image description here

the complete example can found in following link


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -