Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. BUG? Mingw 6.7.0 & Mingw 6.8.0 builds crash on windows

BUG? Mingw 6.7.0 & Mingw 6.8.0 builds crash on windows

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtimerqtimemingw 6.7.0mingw 6.8.0bug
7 Posts 4 Posters 458 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    StudentScripter
    wrote on last edited by
    #1

    So i tried to compile a small timer project, but noticed that even after windeploy the .exe crashes when opened. It doesn't crash in qt creator when beeing run with Mingw 6.7.0 or 6.8.0.

    I tried hunting the line of code down and found it to be:

    QTime time(hours, minutes, seconds);
    QString timeText = time.toString("hh:mm:ss");
    timerLabel->setText(timeText);
    

    Switching it out with this makes it work with Mingw:

    QString timeText = QString::asprintf("%02d:%02d:%02d", hours, minutes, seconds);
    timerLabel->setText(timeText);
    

    Anyway i tried compiling both variants with llvm 6.7.0 afterwards and both variant magically worked!
    I also found this report regarding something similar: https://github.com/msys2/MINGW-packages/issues/22308

    Just wanted to share this finding as it may be relevant for anyone working with QTimer and time formating with Mingw 6.7.0 or 6.8.0.

    I've used Windows 10, 64bit, Qt Creator 14.0.1, Based on Qt 6.7.2 (MSVC 2019, x86_64).

    Here is the full code of the exact programm i tried to build:
    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QLabel>
    #include <QTimer>
    #include <QPushButton>
    #include <QSystemTrayIcon>
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    
    
    private slots:
        void updateTimerDisplay();
        void pushButtonPressed();
    
        void iconActivated(QSystemTrayIcon::ActivationReason reason);
    
    
    private:
        QTimer *timer;
        QLabel *timerLabel;
        QLabel *pauseLabel;
        QPushButton *TimerRestartButton;
        int elapsedSeconds;
        bool was20MinuteTurnus = true;
         void logMessage(const QString &message);
    
        void maximizeWindow();
        void minimizeWindow();
    
    
    
    
        QSystemTrayIcon *trayIcon;
        QMenu *trayIconMenu;
        QAction *minimizeAction;
        QAction *maximizeAction;
        QAction *restoreAction;
        QAction *quitAction;
    };
    #endif // MAINWINDOW_H
    

    maindwindow.cpp:

    #include "mainwindow.h"
    
    #include <QVBoxLayout>
    #include <QHBoxLayout>
    #include <QPushButton>
    #include <QMenu>
    #include <QApplication>
    
    #include <QFile>
    #include <QTextStream>
    
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent), elapsedSeconds(20*60)
    {
    
    
        // Setzen Sie die Mindestgröße des Fensters
        setMinimumSize(900,700);
    
        // Erstellen Sie den Timer
        timer = new QTimer();
        connect(timer, &QTimer::timeout, this, &MainWindow::updateTimerDisplay);
    
        timer->start(1000); // Timer alle 1 Sekunde
    
    
        pauseLabel = new QLabel("PAUSE");
        // Setzen Sie die Schriftgröße
        QFont font2 = pauseLabel->font();
        font2.setPointSize(60); // Größere Schriftgröße
        font2.setBold(true);
        pauseLabel->setFont(font2);
        pauseLabel->setStyleSheet("QLabel { color : red; }");
        pauseLabel->setVisible(false);
    
    
    
    
    
        // Erstellen Sie das QLabel für die Timeranzeige
        timerLabel = new QLabel("00:00:00");
    
    
        // Setzen Sie die Schriftgröße
        QFont font = timerLabel->font();
        font.setPointSize(40); // Größere Schriftgröße
        timerLabel->setFont(font);
    
    
    
    
    
        // Erstellen Sie den Schließen-Button
        TimerRestartButton = new QPushButton("Neustart mit \n 20 Minuten.", this);
        TimerRestartButton->setFixedSize(900 / 8, 700 / 8);
       // connect(TimerRestartButton, &QPushButton::pressed, this, &MainWindow::pushButtonPressed);
        TimerRestartButton->setVisible(false);
        // Setzen Sie die Schriftgröße des Buttons
        QFont buttonFont = TimerRestartButton->font();
        buttonFont.setPointSize(16); // Größere Schriftgröße
        buttonFont.setBold(true); // Fette Schrift
        TimerRestartButton->setFont(buttonFont);
    
        // Erstellen Sie ein zentrales Widget und setzen Sie das Layout
        QWidget *centralWidget = new QWidget(this);
        QVBoxLayout *mainLayout = new QVBoxLayout(centralWidget);
    
        // Erstellen Sie ein horizontales Layout für die Zentrierung
        QHBoxLayout *centerLayout = new QHBoxLayout();
        centerLayout->addStretch(1);
    
        // Erstellen Sie ein vertikales Layout für das Label und den Button
        QVBoxLayout *labelButtonLayout = new QVBoxLayout();
        labelButtonLayout->addWidget(pauseLabel, 0, Qt::AlignCenter);
        labelButtonLayout->addSpacing(15);
        labelButtonLayout->addWidget(timerLabel, 0, Qt::AlignCenter);
        labelButtonLayout->addWidget(TimerRestartButton, 0, Qt::AlignCenter);
    
        // Fügen Sie das vertikale Layout zum horizontalen Layout hinzu
        centerLayout->addLayout(labelButtonLayout);
        centerLayout->addStretch(1);
    
        // Fügen Sie das horizontale Layout zum vertikalen Layout hinzu
        mainLayout->addStretch(1);
        mainLayout->addLayout(centerLayout);
        mainLayout->addStretch(1);
    
        setCentralWidget(centralWidget);
    
    
    
    
    
    
    
        // Erstellen Sie das Systemtray-Icon
        trayIcon = new QSystemTrayIcon(this);
        trayIcon->setIcon(QIcon("://Bilder/KSP Graphic Editor Sketch.png")); // Setzen Sie das Icon-Pfad entsprechend
        trayIcon->setToolTip("Tray Icon Example");
    
        // Erstellen Sie das Kontextmenü für das Systemtray-Icon
        trayIconMenu = new QMenu(this);
        minimizeAction = new QAction("Minimieren", this);
        connect(minimizeAction, &QAction::triggered, this, &MainWindow::minimizeWindow);
        trayIconMenu->addAction(minimizeAction);
    
        maximizeAction = new QAction("Maximieren", this);
        connect(maximizeAction, &QAction::triggered, this, &MainWindow::maximizeWindow);
        trayIconMenu->addAction(maximizeAction);
    
        restoreAction = new QAction("Wiederherstellen", this);
        connect(restoreAction, &QAction::triggered, this, &MainWindow::showNormal);
        trayIconMenu->addAction(restoreAction);
    
        quitAction = new QAction("Beenden", this);
        connect(quitAction, &QAction::triggered, qApp, &QApplication::quit);
        trayIconMenu->addAction(quitAction);
    
        trayIcon->setContextMenu(trayIconMenu);
    
        // Verbinden Sie das Aktivierungs-Signal des Systemtray-Icons
        connect(trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::iconActivated);
    
        // Zeigen Sie das Systemtray-Icon
        trayIcon->show();
    
       // minimizeWindow();
    
    
        logMessage("Constructor startet fully!");
    }
    
    
    
    MainWindow::~MainWindow()
    {
        logMessage("Destructor run!");
    }
    
    
    
    void MainWindow::updateTimerDisplay()
    {
    
        elapsedSeconds--;
        int minutes = elapsedSeconds / 60;
        int seconds = elapsedSeconds % 60;
        int hours = minutes / 60;
        minutes = minutes % 60;
    
    
        /* //PRODUCES ERROR: with Mingw 6.7.0/6.8.0 --> .exe crashes when clicked outside of qtcreator;
           //                                                   BUT works fine when compiled with llvm 6.7.0 (Windows 10, 64bit)
        timerLabel->setText(QString("%1:%2:%3")
                                .arg(hours, 2, 10, QChar('0'))
                                .arg(minutes, 2, 10, QChar('0'))
                                .arg(seconds, 2, 10, QChar('0')));
        */
    
        //WORKS fine with llvm and mingw
        QString timeText = QString::asprintf("%02d:%02d:%02d", hours, minutes, seconds);
        timerLabel->setText(timeText);
    
    
    
        if(elapsedSeconds == 0 && was20MinuteTurnus == true){
            was20MinuteTurnus = false;
            elapsedSeconds = 2*60;
            maximizeWindow();
            pauseLabel->setVisible(true);
    
        }else if(elapsedSeconds == 0 && was20MinuteTurnus == false){
            maximizeWindow();
            timer->stop();
            elapsedSeconds = 0;
            TimerRestartButton->setVisible(true);
            pauseLabel->setVisible(true);
            pauseLabel->setText("Pause zuende. ;)");
            pauseLabel->setStyleSheet("QLabel { color : green; }");
        }
    
    
    
        qDebug() << timerLabel->text();
    
        logMessage("updateTimerDisplay called -- > Elapsed seconds: " + QString::number(elapsedSeconds));
    
    }
    
    
    
    
    void MainWindow::pushButtonPressed()
    {
        if(was20MinuteTurnus == false && elapsedSeconds == 0){
            elapsedSeconds = 20*60;
            was20MinuteTurnus = true;
            timer->start();
            minimizeWindow();
            pauseLabel->setVisible(false);
            pauseLabel->setStyleSheet("QLabel { color : red; }");
            pauseLabel->setText("PAUSE");
        }
    }
    
    void MainWindow::maximizeWindow()
    {
        setWindowState(Qt::WindowMaximized);
        raise();
        activateWindow();
    }
    
    void MainWindow::minimizeWindow()
    {
        setWindowState(Qt::WindowMinimized);
        trayIcon->showMessage("Tray Icon Example", "Application was minimized to Tray", QSystemTrayIcon::Information, 2000);
    }
    
    void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
    {
        switch (reason) {
        case QSystemTrayIcon::Trigger:
            showNormal();
            break;
        case QSystemTrayIcon::DoubleClick:
            showNormal();
            break;
        default:
            break;
        }
    }
    
    
    
    
    void MainWindow::logMessage(const QString &message) {
        QFile logFile("debug_log.txt");
        if (logFile.open(QIODevice::WriteOnly | QIODevice::Append)) {
            QTextStream stream(&logFile);
            stream << message << Qt::endl;
            logFile.close();
        }
    }
    
    
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      StudentScripter
      wrote on last edited by
      #2

      Edit: of course with 6.7.0 , 6.8.0 i mean the version of QT

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        Are you using the official Qt 6.7 or 6.8 binaries from the online installer or Qt libraries provided by MSys?

        S 1 Reply Last reply
        0
        • C ChrisW67

          Are you using the official Qt 6.7 or 6.8 binaries from the online installer or Qt libraries provided by MSys?

          S Offline
          S Offline
          StudentScripter
          wrote on last edited by
          #4

          @ChrisW67 Im using the official binaries from the online installer

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            This is working fine for me with Qt 6.8.1/MinGW 13.1.0/64bit, both from Online installer:

            int main(int argc, char *argv[])
            {
                QCoreApplication a(argc, argv);
                int hours = 10;
                int minutes = 20;
                int seconds = 30;
                auto str = QString("%1:%2:%3")
                               .arg(hours, 2, 10, QChar('0'))
                               .arg(minutes, 2, 10, QChar('0'))
                               .arg(seconds, 2, 10, QChar('0'));
                qDebug() << str;
                return 0;
            }
            

            --> Please provide a minimal, compilable example to reproduce your problem.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            Pl45m4P 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              This is working fine for me with Qt 6.8.1/MinGW 13.1.0/64bit, both from Online installer:

              int main(int argc, char *argv[])
              {
                  QCoreApplication a(argc, argv);
                  int hours = 10;
                  int minutes = 20;
                  int seconds = 30;
                  auto str = QString("%1:%2:%3")
                                 .arg(hours, 2, 10, QChar('0'))
                                 .arg(minutes, 2, 10, QChar('0'))
                                 .arg(seconds, 2, 10, QChar('0'));
                  qDebug() << str;
                  return 0;
              }
              

              --> Please provide a minimal, compilable example to reproduce your problem.

              Pl45m4P Online
              Pl45m4P Online
              Pl45m4
              wrote on last edited by
              #6

              @Christian-Ehrlicher said in BUG? Mingw 6.7.0 & Mingw 6.8.0 builds crash on windows:

              This is working fine for me with Qt 6.8.1/MinGW 13.1.0/64bit, both from Online installer:

              Same for me (Qt 6.7., Win10, MinGW11.2 x64), but what I find weird is that @StudentScripter stated that it only crashes when deploying the code/app and using it outside of the dev environment... So in QtCreator it seems to work for him.
              Also I'm not sure if MSys2 is really involved here or if @StudentScripter uses a plain Windows 10 system.
              (The bug/issue linked above seems to be related to some MSys2 package that was faulty)


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              S 1 Reply Last reply
              0
              • Pl45m4P Pl45m4

                @Christian-Ehrlicher said in BUG? Mingw 6.7.0 & Mingw 6.8.0 builds crash on windows:

                This is working fine for me with Qt 6.8.1/MinGW 13.1.0/64bit, both from Online installer:

                Same for me (Qt 6.7., Win10, MinGW11.2 x64), but what I find weird is that @StudentScripter stated that it only crashes when deploying the code/app and using it outside of the dev environment... So in QtCreator it seems to work for him.
                Also I'm not sure if MSys2 is really involved here or if @StudentScripter uses a plain Windows 10 system.
                (The bug/issue linked above seems to be related to some MSys2 package that was faulty)

                S Offline
                S Offline
                StudentScripter
                wrote on last edited by
                #7

                @Pl45m4 Yes im using a plain windows 10 system. And yes the linked bug is with MSys2 as i searched for a similar problem and this was the only thing related i could find.
                Found it odd myself that i worked inside qt creator but crashed outside (as said i tried windeploy and run dependency walker but haven't found a problem there)

                As said using llvm solves it for me but still wanted to point it out for others may experiencing something simlar.

                @Christian-Ehrlicher i posted all code above simply create a new project and add in my code for maindwindow.h and .cpp. There is nothing else in my project.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved