Skip to content
QtWS25 Call for Papers
  • 0 Votes
    14 Posts
    878 Views
    B

    Just want to summarize the proposed solutions in an orderly fashion so that it remains for the future:

    @Christian-Ehrlicher: use QDate::addDays() / QDate::addMonths() / QDate::addYears(). [for dates]
    example: [qDateTime.setDate(qDateTime.date().addYears(XXX)]

    @JonB : write a global "utility" inline function to do a particular operation you want on a QDateTime.

    @J-Hilk: make a new class and inherit from QDateTime where you add those convenient setX functions.
    don't forget to convert the returning objects from the existing functions that return a QDateTime object to the new object,
    or make a constructor that excepts a QDateTime object as argument, that than can be done implicitly.

    Thank you all for a fruitful discussion and varied and helpful suggestions!

  • 0 Votes
    4 Posts
    948 Views
    T

    @Bonnie said in Showing timer in "hh:mm:ss.zzz" and reset when button clicked:

    I think QElapsedTimer is better for that situation.
    And instead of a static variable in a function, how about make it a member variable that can be used in other member functions.

    in the header, define a member variable of QElapsedTimer

    QElapsedTimer timer;

    in the slot function

    if(!timer.isValid()) timer.start(); QString formattedTime = QTime::fromMSecsSinceStartOfDay(timer.elapsed()).toString("hh:mm:ss.zzz");

    when you "reset" the GUI

    timer.invalidate();

    Thank you very much, that's exactly what I wanted :)

    Do you even have to pause and continue from there or just start and stop/reset?

    And yes, just start and stop/reset.

  • 0 Votes
    1 Posts
    189 Views
    No one has replied
  • 0 Votes
    9 Posts
    2k Views
    mrjjM

    @The178
    Hi
    On your first post
    alt text

  • 0 Votes
    2 Posts
    724 Views
    D

    Ok solved

    It appears that a GLOBAL surface setInterval overrides the setIntervals I did on my glWidget. Kinda weird that the global one overrides local one if local one was specified, is this a bug ?

    format.setSwapInterval(0); QSurfaceFormat::setDefaultFormat(format);

    overrides on widget >

    QSurfaceFormat format; format.setSwapInterval(0); setFormat(format);
  • 0 Votes
    11 Posts
    4k Views
    UnitScanU

    [SOLVED]

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { //… display = new QLabel(this); display->setGeometry(4,4,88,23); display->setText("00:00:00"); //… player = new QMediaPlayer; connect(player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(playerOnMediaStatusChanged(QMediaPlayer::MediaStatus))); //… timer = new QTimer; timer->setTimerType(Qt::PreciseTimer); connect(timer, SIGNAL(timeout()), this, SLOT(timerSlot())); //… } void MainWindow::playerOnMediaStatusChanged(QMediaPlayer::MediaStatus status) { if (status == QMediaPlayer::BufferedMedia) { pos = -1; //int pos declared on .h file timer->start(1000); } } void MainWindow::timerSlot() { pos = pos + 1; QTime time((pos/3600)%60, (pos/60)%60, pos%60); display->setText(time.toString("hh:mm:ss")); }
  • 0 Votes
    6 Posts
    4k Views
    FlacoDanzigerF

    Thanks for you response

  • 0 Votes
    3 Posts
    2k Views
    JKSHJ

    @SGaist said:

    should post this question to the development mailing list. You'll find the Qt's developers/maintainers (this forum is more user oriented)

    A discussion on this topic started on that mailing list yesterday, for those who are interested: http://comments.gmane.org/gmane.comp.lib.qt.devel/23437

  • 0 Votes
    9 Posts
    3k Views
    L

    @mrjj
    sorry, okay im now goign to SOLVED this thread thanks @SGaist @mrjj

  • 0 Votes
    17 Posts
    14k Views
    B

    @sirop It's set, I've checked it like this:

    void MainWindow::timerUpdate() { static int start = 0; static const size_t loops = 10000; static qint64 nsecs[loops]; static size_t index = 0; static QElapsedTimer* elapsed = new QElapsedTimer(); if(start++ < 10) { elapsed->restart(); qDebug() << "clockType: " << elapsed->clockType(); return; } if(index<loops) { nsecs[index++]=elapsed->nsecsElapsed(); elapsed->restart(); return; } timer->stop(); qint64 maxDev = 0; qint64 avgDev = 0; for( qint64 elapsedTime : nsecs ) { //qDebug() << "Time since last update" << elapsedTime << "nanoseconds"; qint64 dev = 5000000 - elapsedTime; if(dev < 0) { dev = dev*-1; } avgDev += dev; if( dev > maxDev) maxDev = dev; } qDebug() << "Max deviation: " << maxDev; qDebug() << "Avg deviation: " << avgDev/loops; }

    With following output:

    clockType: 4 Max deviation: 4615989 Avg deviation: 4327