找回密码
 立即注册
收起左侧

关于判断数据是否相同的问题

10
回复
9174
查看
[复制链接]
累计签到:132 天
连续签到:1 天
来源: 2015-3-31 21:33:40 显示全部楼层 |阅读模式
1Qter豆
从txt中读取这些数据,
10:14:42 $GPDTM,W84,,0.0,N,0.0,E,0.0,W84*6F
10:14:43 $GPRMC,101443.00,A,4155.48410,N,12323.86670,E,0.049,255.81,160411,,,A*6A
10:14:43 $GPVTG,255.81,T,,M,0.049,N,0.090,K,A*32
10:14:44 $GPRMC,101444.00,A,4155.48380,N,12323.86717,E,0.040,251.46,160411,,,A*65
10:14:44 $GPVTG,251.46,T,,M,0.040,N,0.073,K,A*39
10:14:44 $GPGGA,101444.00,4155.48380,N,12323.86717,E,1,05,11.26,89.6,M,7.8,M,,*6D
这只是一部分,然后按照时间相同的一起再发到textBrowser上,比如判断第一个和第二个时间不同,然后就发第一条,再判断第二个和第三个依次判断相同的一起发,时间间隔是一秒。
我现在会读取数据,但是不知道怎么做能把时间相同的一起发而且还要间隔一秒再发下一批一样的。

最佳答案

查看完整内容

QTime QTime::fromString(const QString & string, const QString & format) [static] Returns the QTime represented by the string, using the format given, or an invalid time if the string cannot be parsed. These expressions may be used for the format: Expression Output h the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display) hh the hour with a leading zero (00 to 23 or 01 to 12 if AM ...
回复

使用道具 举报

尚未签到

2015-3-31 21:33:41 显示全部楼层
adaluobo 发表于 2015-4-4 13:25
我是用QStringList strlist=data.split("$");
QStringList b=strlist[0].split(":");
int c=b[0].toInt() ...

QTime QTime::fromString(const QString & string, const QString & format) [static]
Returns the QTime represented by the string, using the format given, or an invalid time if the string cannot be parsed.

These expressions may be used for the format:

Expression        Output
h        the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
hh        the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
m        the minute without a leading zero (0 to 59)
mm        the minute with a leading zero (00 to 59)
s        the second without a leading zero (0 to 59)
ss        the second with a leading zero (00 to 59)
z        the milliseconds without leading zeroes (0 to 999)
zzz        the milliseconds with leading zeroes (000 to 999)
AP        interpret as an AM/PM time. AP must be either "AM" or "PM".
ap        Interpret as an AM/PM time. ap must be either "am" or "pm".


文档里面写的很清楚怎么用哦。。。   你用这个解析时间就行了
回复

使用道具 举报

尚未签到

2015-3-31 22:08:40 显示全部楼层
截取前面固定长度来判断不行么
回复

使用道具 举报

累计签到:132 天
连续签到:1 天
2015-4-1 07:56:16 显示全部楼层
Joey_Chan 发表于 2015-3-31 22:08
截取前面固定长度来判断不行么

我之前是把时间按分离出来了,然后只判断时间,但是会少数据,而且是一下在发出来。这是我的代码:
void MainWindow::timerDone()
{
      QFile file("GPS.txt");
      if (!file.open(QIODevice::ReadOnly  | QIODevice::Text))
               return;
        QTextStream read(&file);  //输入流对象  read
        QString data1,data2;

        while(!file.atEnd())
        {
            data1=file.readLine();
            QStringList strlisti=data1.split("  $");
            data2=file.readLine();
            QStringList strlistj=data2.split("  $");

                for(i=0,j=1;i<1,j<2;i++,j++)
                {
                    if(strlisti[0]==strlistj[0])
                    {
                        ui->textBrowser->insertPlainText(data1);
                        ui->textBrowser->insertPlainText(data2);
                    }
                    else
                        ui->textBrowser->insertPlainText(data1);

                }


         }


        if(file.atEnd()){
             timer->stop();
           file.close();}

}
图片是运行结果

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

尚未签到

2015-4-1 09:46:10 显示全部楼层
adaluobo 发表于 2015-4-1 07:56
我之前是把时间按分离出来了,然后只判断时间,但是会少数据,而且是一下在发出来。这是我的代码:
void  ...

你说的少数据是因为这个吧。。。
  1.      else
  2.                         ui->textBrowser->insertPlainText(data1);
复制代码
你只放了data1, 那data2 呢?
回复

使用道具 举报

累计签到:132 天
连续签到:1 天
2015-4-1 12:47:38 显示全部楼层
Joey_Chan 发表于 2015-4-1 09:46
你说的少数据是因为这个吧。。。你只放了data1, 那data2 呢?

我遇到问题是,它只能比较两条,然后就直接读取第三条,比较第三条和第四条,不会去比较第二条和第三条,这样就丢数据了
回复

使用道具 举报

累计签到:595 天
连续签到:1 天
2015-4-1 17:42:06 显示全部楼层
逻辑问题吧,没仔细看看到,猜的。
回复

使用道具 举报

尚未签到

2015-4-1 20:19:39 显示全部楼层
adaluobo 发表于 2015-4-1 12:47
我遇到问题是,它只能比较两条,然后就直接读取第三条,比较第三条和第四条,不会去比较第二条和第三条, ...

这样的话,你不如先把每条都取出来,变成一个数组,这样你一个个对比数组元素不就行了
回复

使用道具 举报

累计签到:132 天
连续签到:1 天
2015-4-2 19:19:36 显示全部楼层
Joey_Chan 发表于 2015-4-1 20:19
这样的话,你不如先把每条都取出来,变成一个数组,这样你一个个对比数组元素不就行了 ...

我把时间分离出来之后,都化为秒,但是总会提示超出范围
回复

使用道具 举报

尚未签到

2015-4-2 19:40:49 显示全部楼层
adaluobo 发表于 2015-4-2 19:19
我把时间分离出来之后,都化为秒,但是总会提示超出范围

QTime 不是有个自定义格式的么

而且出来的是qint64, 足够长了
回复

使用道具 举报

累计签到:132 天
连续签到:1 天
2015-4-4 13:25:56 显示全部楼层
Joey_Chan 发表于 2015-4-2 19:40
QTime 不是有个自定义格式的么

而且出来的是qint64, 足够长了

我是用QStringList strlist=data.split("$");
QStringList b=strlist[0].split(":");
int c=b[0].toInt()*3600+b[1].toInt()*60+b[1].toInt();

l来实现时间分离并化为秒的,然后b就超出范围....
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了