- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试扩展 QTime
类以覆盖 toString()
函数。
-----编辑-----我真正需要的是一种只显示十分之一/百分之一秒而不是毫秒的简洁方法。我目前的解决方案是这样的:
QString original = qtime.toString("ss.zzz");
QString tenths = original.left(original.size() - 2); // discards hundredths and msecs
我想做的是:
QString tenths = fooTime.myToString("ss.x"); // discards hundredths and msecs
---编辑----
这个类如下所示:
class FooTime : public QTime
{
public:
FooTime()
{}
FooTime(int h, int m, int s = 0, int ms = 0)
: QTime(h, m, s, ms)
{}
QString toString(const QString& format) const // the function I need to override
{
return format + " foo";
}
FooTime& operator=(const FooTime& t)
{
// ??? see below.
}
};
不幸的是,QTime
在这些函数中有一个棘手的行为:
class QTime
{
...
QTime addMSecs(int ms) const;
QTime addSecs(int s) const;
...
}
所以实际上我写不出下面的代码:
...
FooTime t(0, 0);
t = t.addMSecs(1000); // compile error, no match for 'operator=' (operand types are 'FooTime' and 'QTime')
问题是 FooTime
是 QTime
,但 QTime
不是 FooTime
。
如何覆盖 FooTime
运算符 =
以解决此问题?
最佳答案
QTime
的派生是一种完全错误的方法。如果您需要以不同方式格式化时间,只需编写一个独立函数:
QString myTimeFormat(const QTime & time) {
const QString str = time.toString("ss.zzz");
return str.left(str.size() - 2);
}
面向对象并不是万能的锤子。有时一个普通的旧函数就可以了。
关于c++ - 继承QTime,自定义时间格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21160351/
我正在编写一个程序,要求用户等待大量秒数并等待那么多秒数。问题是一旦 waitSecs 大于 9999 秒,launchTime 似乎变成了一个随机数。我已经使用 qDebug 输出了 waitSec
我正在使用 QT5.51。为什么t1无效?: QTime t1 = QTime().addSecs(122); qDebug() << t1.isValid() << t1.toString("hh:
这更像是一个普通的 C++ 初学者问题: 我有 2 个类: A 类,包括“ReadData”方法,一旦 TCP 套接字接收到新数据就会调用该方法 B 类,包括通过 TCP 发送大量数据的方法“开始”。
我对这个 QT 东西很陌生。这可能是一个愚蠢的问题,但我找不到任何答案。我浏览了 qt 文档并在互联网上搜索以找到这个问题的答案。 我的问题是,假设有一个“整数变量”,其持续时间值以秒为单位。我需要将
我正在编写简单的 pomodoro 应用程序,它基本上是倒数计时器。现在,我已经开始倒计时了,但奇怪的是,当我向我的类(任意)添加另一个属性时,我得到了Sedmentation fault错误。 使用
我正在尝试在 python 中做一个时间计数器使用 QTime并在 QLabel 中显示这次使用 PyQt .我需要这样做,以显示自从我的程序开始工作以来已经过去了多少时间,使用这种时间格式:00:0
如何将 QTime 转换为秒数?我已使用 time.setHMS(0,1,0); 手动设置时间 现在,当我将此变量 time 转换为 integer 时,我想要得到 60 秒。我该如何实现? 最佳答案
在 HAProxy 1.6.3-1ubuntu0.1 后面运行 Web 应用程序,我得到了 haproxy 统计信息 qtime,ctime,rtime,ttime 0,0,0,2704 的值. 来自
在我的游戏中,我需要一个秒表来测量和显示耗时。 为此,我制作了一个简单的小部件: ZuulStopwatchWidget::ZuulStopwatchWidget(QWidget *paren
我们使用 haproxy 1.5.14 作为 HTTP 的负载平衡器以及多个域主机名的 HTTPS 端点。对于 HTTPS 端点,我们使用 SSL NI header 检查来找出正确的后端节点。 在我
我没时间添加功能来工作。我正在使用 Qt4。这是代码片段,它产生两个相同的时间而不是 100 秒的不同。 void main() { QTextStream out (stdout); Q
我在 SQL Server Express 中有一个包含字段 name varchar(10) 的表和 timeVar time我想保存 QTime 的值time 中的变量字段。 这是我试过的: QT
我正在尝试使用 qwtplot 绘制速度-时间图形。 我的X数据是QTime值,Y数据是相应的速度值。我找不到任何关于用 QTime 绘图的例子。谁能简单解释一下如何绘制 QTime 与 Y 数据?如
我在 Qt 中有一个 GUI C++ Class,它有一个 SLOT,它在 QGridLayout 中添加了一组文本框和标签。该数组是方形的,具体取决于变量 n。即,如果 n == 10 那么 QGr
我正在尝试设置两个时间编辑:“timeEdit”和“timeEdit_2”。 "timeEdit_2"取当前时间如下: ui->timeEdit_2->setTime(QTime::currentTi
我一直在研究一个简单的对话框小部件,它应该以 10 赫兹的速率显示 GMT 时间。由于我正在使用的系统运行了好几天,它应该是稳定的。 在一些通宵运行中,我注意到我的“BAR”程序在执行几个小时后以 1
我是一名优秀的程序员,十分优秀!