Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Open file via double-click
Qt 6.12 LTS is out! See what's new in the release blog

Open file via double-click

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 5 Posters 16.9k Views 2 Watching
  • 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.
  • JonBJ JonB

    @UnitScan said in Open file via double-click:

    Yes, the app crashes if I try to launch it from the command line, while launching it via Explorer it works fine.

    And earlier you wrote:

    but when I open them "externally" with the double click the program crashes.

    How are these two statements consistent?

    Well that sounds strange, doesn't it? The only difference should be what Explorer passes on the command-line. Maybe you've written your program to expect the right thing(s) in argv, I don't know. Have you done this? When you do not run from File Explorer, what arguments are you passing it?

    If it crashes from command-line, won't it do so from Creator debugger, where you can see the stack trace?

    Otherwise, put some qDebug() statements into it (starting from the very first line in main()) to see where it's getting to. If anywhere.

    UnitScanU Offline
    UnitScanU Offline
    UnitScan
    wrote on last edited by UnitScan
    #11

    @JonB said in Open file via double-click:

    @UnitScan said in Open file via double-click:

    Yes, the app crashes if I try to launch it from the command line, while launching it via Explorer it works fine.

    And earlier you wrote:

    but when I open them "externally" with the double click the program crashes.

    How are these two statements consistent?

    Let me explain: if I double click on the exe file via Explorer, it starts regularly. If I launch it via cmd it crashes instead.
    If I double click on any audio file, the program opens but crashes immediately

    JonBJ 1 Reply Last reply
    0
    • UnitScanU UnitScan

      @JonB said in Open file via double-click:

      @UnitScan said in Open file via double-click:

      Yes, the app crashes if I try to launch it from the command line, while launching it via Explorer it works fine.

      And earlier you wrote:

      but when I open them "externally" with the double click the program crashes.

      How are these two statements consistent?

      Let me explain: if I double click on the exe file via Explorer, it starts regularly. If I launch it via cmd it crashes instead.
      If I double click on any audio file, the program opens but crashes immediately

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #12

      @UnitScan

      If I launch it via cmd it crashes instead.

      So what happens if you launch it from Creator debugger, like I asked?

      Put in some qDebug() statements to see if it gets as far as your main, and then where.

      1 Reply Last reply
      1
      • UnitScanU Offline
        UnitScanU Offline
        UnitScan
        wrote on last edited by UnitScan
        #13

        I did as you asked, and this is the result:

        #include "mainwindow.h"
        #include <QApplication>
        #include <QTimer>
        #include <stdio.h>
        #include <iostream>
        
        int main(int argc, char *argv[])
        {
            for (int i = 0; i < argc; ++i) {
                std::cout << "The " << i << "th argument is " << argv[i] << std::endl;
            }
            QApplication a(argc, argv);
            MainWindow w;
            QTimer::singleShot(0, & w, SLOT(initialize()));
            w.show();
        
            return a.exec();
        }
        

        Application output in Debug mode:

        ASSERT failure in QList<T>::at: "index out of range", file C:/Qt/Qt5.14.0/5.14.0/mingw73_32/include/QtCore/qlist.h, line 571
        
        JonBJ ODБOïO 2 Replies Last reply
        0
        • UnitScanU UnitScan

          I did as you asked, and this is the result:

          #include "mainwindow.h"
          #include <QApplication>
          #include <QTimer>
          #include <stdio.h>
          #include <iostream>
          
          int main(int argc, char *argv[])
          {
              for (int i = 0; i < argc; ++i) {
                  std::cout << "The " << i << "th argument is " << argv[i] << std::endl;
              }
              QApplication a(argc, argv);
              MainWindow w;
              QTimer::singleShot(0, & w, SLOT(initialize()));
              w.show();
          
              return a.exec();
          }
          

          Application output in Debug mode:

          ASSERT failure in QList<T>::at: "index out of range", file C:/Qt/Qt5.14.0/5.14.0/mingw73_32/include/QtCore/qlist.h, line 571
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #14

          @UnitScan
          You must run it in the debugger, from Creator, not just compile for debug. Then when the ASSERT is hit and the debugger traps it you will find there is a stack trace window. That will show the qlist.h line, and then trace back through all the levels to some line in your code, which is what was being executed when the ASSERT happened.

          And please use qDebug() for debug output statements, not std::cout.

          Separately, since you persist in using SLOT(), all bets are off as to how that might behave at runtime.

          And finally, I hope you know what you're doing with seemingly initializing on a timer, seems hokey to me. You sure you understand exactly when initialize() will be executed, compared to other initializations (like in constructors) you are doing?

          1 Reply Last reply
          1
          • UnitScanU UnitScan

            I did as you asked, and this is the result:

            #include "mainwindow.h"
            #include <QApplication>
            #include <QTimer>
            #include <stdio.h>
            #include <iostream>
            
            int main(int argc, char *argv[])
            {
                for (int i = 0; i < argc; ++i) {
                    std::cout << "The " << i << "th argument is " << argv[i] << std::endl;
                }
                QApplication a(argc, argv);
                MainWindow w;
                QTimer::singleShot(0, & w, SLOT(initialize()));
                w.show();
            
                return a.exec();
            }
            

            Application output in Debug mode:

            ASSERT failure in QList<T>::at: "index out of range", file C:/Qt/Qt5.14.0/5.14.0/mingw73_32/include/QtCore/qlist.h, line 571
            
            ODБOïO Offline
            ODБOïO Offline
            ODБOï
            wrote on last edited by
            #15

            @UnitScan hi

            @UnitScan said in Open file via double-click:

            argv[i]

            this is the kind of code that can cause "index out of range" error.
            you can use
            https://doc.qt.io/qt-5/qcoreapplication.html#arguments
            or
            https://doc.qt.io/qt-5/qcommandlineparser.html
            to retrive the arguments

            JonBJ 1 Reply Last reply
            0
            • ODБOïO ODБOï

              @UnitScan hi

              @UnitScan said in Open file via double-click:

              argv[i]

              this is the kind of code that can cause "index out of range" error.
              you can use
              https://doc.qt.io/qt-5/qcoreapplication.html#arguments
              or
              https://doc.qt.io/qt-5/qcommandlineparser.html
              to retrive the arguments

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #16

              @LeLev
              In this case he is using main(argc, argv) correctly. The point (to me) is:

              ASSERT failure in QList<T>::at: "index out of range", file C:/Qt/Qt5.14.0/5.14.0/mingw73_32/include/QtCore/qlist.h, line 571
              

              I don't see how that can arise from his argc/argv/std::cout loop. Has to be a QList involved!

              ODБOïO 1 Reply Last reply
              1
              • UnitScanU Offline
                UnitScanU Offline
                UnitScan
                wrote on last edited by UnitScan
                #17

                @JonB well, I found the origin of the assert failure

                void MainWindow::performStyles()
                {
                    QString theme = settings->value("app/theme").toString();
                    settings->beginGroup("themes");
                    QStringList colors = settings->value(theme).toString().split(",");
                    settings->endGroup();
                    QString stylesheet = (
                                "QSlider::groove:horizontal {"
                                "border: 1px solid #999999;"
                                "height: 5px;"
                                "background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #c4c4c4);"
                                "border-radius: 3px;"
                                "}"
                                "QSlider::handle:horizontal {"
                                "background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4, stop:1 %3);"
                                "border: 1px solid #5c5c5c;"
                                "width: 16px;"
                                "margin: -2px 0;"
                                "border-radius: 3px;"
                                "}"
                                "QSlider::handle:horizontal:hover {"
                                "background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #FFFFFF, stop:1 %3);"
                                "border: 1px solid #808080;"
                                "width: 16px;"
                                "margin: -2px 0;"
                                "border-radius: 3px;"
                                "}"
                                "QSlider::add-page:horizontal {"
                                "background: #c0c0c0;"
                                "border-radius: 3px;"
                                "margin: 0 -1px;"
                                "}"
                                "QSlider::sub-page:horizontal {"
                                "background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4, stop:1 %3);"
                                "border-radius: 3px;"
                                "}"
                                "QFrame#data {"
                                "border: 1px solid gray;"
                                "border-radius: 5px;"
                                "background-color: %1;"
                                "}"
                                "QLabel#display {"
                                "font-size: 20px;"
                                "color: %2;"
                                "padding-bottom: 1px;"
                                "background-color: %1;"
                                "}"
                                "QLabel#kbps, QLabel#hz, QLabel#channels  {"
                                "font-size: 10px;"
                                "text-align: center;"
                                "color: %2;"
                                "}"
                                "ScrollText {"
                                "font-size: 14px;"
                                "text-align: center;"
                                "color: %2;"
                                "}"
                                "QTableView {"
                                "border: 1px solid gray;"
                                "border-radius: 5px;"
                                "background-color: %1;"
                                "color: %2;"
                                "}"
                                "QTableView::item:selected {"
                                "border-radius: 3px;"
                                "background-color: %2;"
                                "color: %1;"
                                "}"
                                "QScrollBar#vscrollbar:vertical {"
                                "border: 1px solid grey;"
                                "border-radius: 3px;"
                                "background: %1;"
                                "width: 15px;"
                                "margin: 0px 0 0px 0;"
                                "}"
                                "QScrollBar#vscrollbar::handle:vertical {"
                                "background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4, stop:1 %1);"
                                "border: 1px solid #5c5c5c;"
                                "width: 16px;"
                                "min-height: 16px;"
                                "border-radius: 3px;"
                                "}"
                                "QScrollBar#vscrollbar::add-line:vertical {"
                                "border: 0px solid grey;"
                                "background: #32CC99;"
                                "height: 0px;"
                                "subcontrol-position: bottom;"
                                "subcontrol-origin: margin;"
                                "}"
                                "QScrollBar#vscrollbar::sub-line:vertical {"
                                "border: 0px solid grey;"
                                "background: #32CC99;"
                                "height: 0px;"
                                "subcontrol-position: top;"
                                "subcontrol-origin: margin;"
                                "}"
                                "QScrollBar#vscrollbar::add-page:vertical, QScrollBar::sub-page:vertical {"
                                "background: none;"
                                "}"
                                "QListWidget::item:selected {"
                                "background-color: none;"
                                "border: 3px solid grey;"
                                "}"
                                "QListWidget::item:selected { background: transparent; }"
                                "QListWidget::item:selected { border: 1px solid red; }"
                                );
                    this->setStyleSheet(stylesheet.arg(colors.at(0),colors.at(1),colors.at(2)));
                }
                

                This seems to be the line causing the error

                this->setStyleSheet(stylesheet.arg(colors.at(0),colors.at(1),colors.at(2)));
                

                My ini settings file is written like this

                [themes]
                Red="#C21212,#ffffff,#C21212"
                

                I must have misused the QString arg method

                JonBJ 1 Reply Last reply
                0
                • JonBJ JonB

                  @LeLev
                  In this case he is using main(argc, argv) correctly. The point (to me) is:

                  ASSERT failure in QList<T>::at: "index out of range", file C:/Qt/Qt5.14.0/5.14.0/mingw73_32/include/QtCore/qlist.h, line 571
                  

                  I don't see how that can arise from his argc/argv/std::cout loop. Has to be a QList involved!

                  ODБOïO Offline
                  ODБOïO Offline
                  ODБOï
                  wrote on last edited by
                  #18

                  @JonB yes you are right, my bad.
                  i thought about argv[i] as a QList for some reason

                  1 Reply Last reply
                  0
                  • UnitScanU UnitScan

                    @JonB well, I found the origin of the assert failure

                    void MainWindow::performStyles()
                    {
                        QString theme = settings->value("app/theme").toString();
                        settings->beginGroup("themes");
                        QStringList colors = settings->value(theme).toString().split(",");
                        settings->endGroup();
                        QString stylesheet = (
                                    "QSlider::groove:horizontal {"
                                    "border: 1px solid #999999;"
                                    "height: 5px;"
                                    "background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #c4c4c4);"
                                    "border-radius: 3px;"
                                    "}"
                                    "QSlider::handle:horizontal {"
                                    "background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4, stop:1 %3);"
                                    "border: 1px solid #5c5c5c;"
                                    "width: 16px;"
                                    "margin: -2px 0;"
                                    "border-radius: 3px;"
                                    "}"
                                    "QSlider::handle:horizontal:hover {"
                                    "background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #FFFFFF, stop:1 %3);"
                                    "border: 1px solid #808080;"
                                    "width: 16px;"
                                    "margin: -2px 0;"
                                    "border-radius: 3px;"
                                    "}"
                                    "QSlider::add-page:horizontal {"
                                    "background: #c0c0c0;"
                                    "border-radius: 3px;"
                                    "margin: 0 -1px;"
                                    "}"
                                    "QSlider::sub-page:horizontal {"
                                    "background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4, stop:1 %3);"
                                    "border-radius: 3px;"
                                    "}"
                                    "QFrame#data {"
                                    "border: 1px solid gray;"
                                    "border-radius: 5px;"
                                    "background-color: %1;"
                                    "}"
                                    "QLabel#display {"
                                    "font-size: 20px;"
                                    "color: %2;"
                                    "padding-bottom: 1px;"
                                    "background-color: %1;"
                                    "}"
                                    "QLabel#kbps, QLabel#hz, QLabel#channels  {"
                                    "font-size: 10px;"
                                    "text-align: center;"
                                    "color: %2;"
                                    "}"
                                    "ScrollText {"
                                    "font-size: 14px;"
                                    "text-align: center;"
                                    "color: %2;"
                                    "}"
                                    "QTableView {"
                                    "border: 1px solid gray;"
                                    "border-radius: 5px;"
                                    "background-color: %1;"
                                    "color: %2;"
                                    "}"
                                    "QTableView::item:selected {"
                                    "border-radius: 3px;"
                                    "background-color: %2;"
                                    "color: %1;"
                                    "}"
                                    "QScrollBar#vscrollbar:vertical {"
                                    "border: 1px solid grey;"
                                    "border-radius: 3px;"
                                    "background: %1;"
                                    "width: 15px;"
                                    "margin: 0px 0 0px 0;"
                                    "}"
                                    "QScrollBar#vscrollbar::handle:vertical {"
                                    "background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #b4b4b4, stop:1 %1);"
                                    "border: 1px solid #5c5c5c;"
                                    "width: 16px;"
                                    "min-height: 16px;"
                                    "border-radius: 3px;"
                                    "}"
                                    "QScrollBar#vscrollbar::add-line:vertical {"
                                    "border: 0px solid grey;"
                                    "background: #32CC99;"
                                    "height: 0px;"
                                    "subcontrol-position: bottom;"
                                    "subcontrol-origin: margin;"
                                    "}"
                                    "QScrollBar#vscrollbar::sub-line:vertical {"
                                    "border: 0px solid grey;"
                                    "background: #32CC99;"
                                    "height: 0px;"
                                    "subcontrol-position: top;"
                                    "subcontrol-origin: margin;"
                                    "}"
                                    "QScrollBar#vscrollbar::add-page:vertical, QScrollBar::sub-page:vertical {"
                                    "background: none;"
                                    "}"
                                    "QListWidget::item:selected {"
                                    "background-color: none;"
                                    "border: 3px solid grey;"
                                    "}"
                                    "QListWidget::item:selected { background: transparent; }"
                                    "QListWidget::item:selected { border: 1px solid red; }"
                                    );
                        this->setStyleSheet(stylesheet.arg(colors.at(0),colors.at(1),colors.at(2)));
                    }
                    

                    This seems to be the line causing the error

                    this->setStyleSheet(stylesheet.arg(colors.at(0),colors.at(1),colors.at(2)));
                    

                    My ini settings file is written like this

                    [themes]
                    Red="#C21212,#ffffff,#C21212"
                    

                    I must have misused the QString arg method

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #19

                    @UnitScan
                    Your colors.at() expressions are fine so long as

                    QStringList colors = settings->value(theme).toString().split(",");
                    

                    really does returns 3 colors. My guess is that, depending on how you run the program --- e.g do you read from "the current working directory"? or, what is qDebug() << theme, or qDebug() << settings->value(theme).toString()? --- you're not picking up the right thing? Code like yours which relies on 3 elements from the split() should have a Q_ASSERT(colors.count() == 3);. Anyway, somehow that differs when you run your code in different ways.

                    I hope now that you have found using the debugger helps find such errors!

                    1 Reply Last reply
                    3
                    • UnitScanU Offline
                      UnitScanU Offline
                      UnitScan
                      wrote on last edited by
                      #20

                      I suppose the problem is bigger: when I run the program via cmd it doesn't even load the icons: https://i.imgur.com/yqvpYnl.png

                      1 Reply Last reply
                      0
                      • sierdzioS Offline
                        sierdzioS Offline
                        sierdzio
                        Moderators
                        wrote on last edited by
                        #21

                        as @JonB pointed out, this is probably related to working directory. Make sure you load your settings from the right path! This might come in handy: https://doc.qt.io/qt-5/qcoreapplication.html#applicationDirPath

                        (Z(:^

                        UnitScanU 1 Reply Last reply
                        4
                        • sierdzioS sierdzio

                          as @JonB pointed out, this is probably related to working directory. Make sure you load your settings from the right path! This might come in handy: https://doc.qt.io/qt-5/qcoreapplication.html#applicationDirPath

                          UnitScanU Offline
                          UnitScanU Offline
                          UnitScan
                          wrote on last edited by
                          #22

                          @sierdzio said in Open file via double-click:

                          as @JonB pointed out, this is probably related to working directory. Make sure you load your settings from the right path! This might come in handy: https://doc.qt.io/qt-5/qcoreapplication.html#applicationDirPath

                          Thank you very much!

                          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
                          • Unsolved