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. Crash on launch with file on Mac
QtWS25 Last Chance

Crash on launch with file on Mac

Scheduled Pinned Locked Moved General and Desktop
19 Posts 5 Posters 8.9k 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.
  • A Offline
    A Offline
    aaronsher
    wrote on last edited by
    #2

    OK, let's ask this question another way, then. Has anybody used the FileOpenEvent on the Mac? Can anyone provide any sample code that's known to work?

    Thanks,
    Aaron

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #3

      I never used that feature myself. You might want to have a look at the demos/browser demo in the Qt sources. It uses QFileOpenEvent to open HTML pages in that demo browser.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aaronsher
        wrote on last edited by
        #4

        Appreciate the response. I did look at the browser sample, and it looks to me like they're doing the same thing that I'm doing. I may need to fall back to the old approach of incrementally changing their code into my code, but it's so different that I was hoping to avoid that.

        Thanks,
        Aaron

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #5

          Oh. Just looking at your stack trace: Can you provide the exact declaration and implementation of you constructors of your derived QApplication subclass, please? I have a guess what might be wrong here.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • A Offline
            A Offline
            aaronsher
            wrote on last edited by
            #6

            Here's what I've got at the moment. Note that the crash still happens without any of the code in the body of either function.

            @
            explicit MapMakerApplication(int argc, char **argv);
            ~MapMakerApplication();

            MapMakerApplication::MapMakerApplication(int argc, char **argv)
            : QApplication(argc, argv)
            {
            logFile = fopen("/Users/asher/logs/MMLog.txt", "a");
            fprintf(logFile, "------------------------------------------------------------------\nStarting log\n");
            fflush(logFile);
            }
            MapMakerApplication::~MapMakerApplication()
            {
            for (int i = 0; i < _windows.size(); ++i)
            delete _windows.at(i);
            _windows.clear();
            }@

            If it helps, I'm never actually getting the FileOpenEvent before the crash. However, if I start the application directly or through the debugger, it launches fine.

            Thanks,
            Aaron

            1 Reply Last reply
            0
            • A Offline
              A Offline
              aaronsher
              wrote on last edited by
              #7

              Just to be clear, though, if I don't subclass QApplication, I have no trouble, so it's something about the structure of this class.

              Aaron

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #8

                Ok, exactly what I have guessed. Your problem has nothing to do with the QFileOpenEvent. Just change your constructor signature

                from

                @
                explicit MapMakerApplication(int argc, char **argv);
                @

                to

                @
                explicit MapMakerApplication(int &argc, char **argv);
                @

                Note the reference ampersand for argc! There are some threads around in the forums that explain the faulty behavior. Basically it's due to QCoreApplication's requirement of argc to stay valid during its lifetime, which is not the case for pass-by-value arguments.

                PS:

                [quote author="aaronsher" date="1342628763"]Just to be clear, though, if I don't subclass QApplication, I have no trouble, so it's something about the structure of this class.
                [/quote]

                Which proofs my guess even more ;-)

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  aaronsher
                  wrote on last edited by
                  #9

                  Cool, thanks! Wow, that's one I never would have guessed, though looking again at the browser sample I see that they are doing that and I missed it the first time.

                  Aaron

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #10

                    You're welcome. And you're not the first who stepped into that trap :-)

                    I've added doc notes the QCoreApplication and QApplication documentation here on DevNet.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mickael.cruz
                      wrote on last edited by
                      #11

                      Hello,
                      I have a similar problem but I can't find this "browser" demo. Can someone tell me which folder is it in?

                      Thanks

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        aaronsher
                        wrote on last edited by
                        #12

                        It's under the QtSDK in Demos/4.7/browser in my install.

                        Aaron

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          mickael.cruz
                          wrote on last edited by
                          #13

                          Aah so this demo is QT 4.7 specific! I am using Qt 4.8 and this demo wasn't available. I just downloaded the 4.7 version to get the demo. Thank you.

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            prabuqt
                            wrote on last edited by
                            #14

                            [quote author="aaronsher" date="1342629125"]Cool, thanks! Wow, that's one I never would have guessed, though looking again at the browser sample I see that they are doing that and I missed it the first time.

                            Aaron[/quote]

                            Please mark the title as Solved :)

                            1 Reply Last reply
                            0
                            • M Offline
                              M Offline
                              mickael.cruz
                              wrote on last edited by
                              #15

                              [SOLVED] How do I do that?

                              1 Reply Last reply
                              0
                              • P Offline
                                P Offline
                                prabuqt
                                wrote on last edited by
                                #16
                                1. Click on the title of your post
                                  you will find this below the left side of your title.

                                quote |link |edit |report

                                1. click on edit
                                2. Prefix the title by adding a tag like [SOLVED] and update the post.

                                Thank you.

                                1 Reply Last reply
                                0
                                • P Offline
                                  P Offline
                                  prabuqt
                                  wrote on last edited by
                                  #17

                                  bq. [SOLVED] How do I do that?

                                  looks great mickael.cruz

                                  1 Reply Last reply
                                  0
                                  • W Offline
                                    W Offline
                                    Wael
                                    wrote on last edited by
                                    #18

                                    Hi All,
                                    I am getting very similar crash using Qt 4.8.5 on OSX 10.9

                                    When I double click my file in Finder while my application is running it opens correctly, but if my application is not already running I get a crash just after showing its splash screen, note that I am using the correct int& argc in my inherited QApplication

                                    Part of the crash stack:

                                    Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
                                    0 QtCore 0x000000010315614a QString::fromLocal8Bit(char const*, int) + 42
                                    1 QtCore 0x000000010321d9cc QCoreApplication::arguments() + 124
                                    2 QtGui 0x000000010356a77f QMacInputContext::reset() + 49311
                                    3 com.apple.AppKit 0x00007fff8810ef65 __69-[NSApplication(NSAppleEventHandling) _handleAEOpenDocumentsForURLs:]_block_invoke + 1651
                                    4 com.apple.AppKit 0x00007fff87f0ac63 __78-[NSDocumentController(NSInternal) _autoreopenDocumentsWithCompletionHandler:]_block_invoke_2 + 140
                                    5 com.apple.AppKit 0x00007fff87f0a84d -[NSDocumentController(NSInternal) _autoreopenDocumentsWithCompletionHandler:] + 746
                                    6 com.apple.AppKit 0x00007fff87d759fb -[NSApplication _reopenWindowsAsNecessaryIncludingRestorableState:registeringAsReady:completionHandler:] + 323
                                    7 com.apple.AppKit 0x00007fff8810e869 -[NSApplication(NSAppleEventHandling) _handleAEOpenDocumentsForURLs:] + 306
                                    8 com.apple.AppKit 0x00007fff87d752bb -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 450
                                    9 com.apple.Foundation 0x00007fff89a0eeaa -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 294
                                    10 com.apple.Foundation 0x00007fff89a0ed1d _NSAppleEventManagerGenericHandler + 106
                                    11 com.apple.AE 0x00007fff83d55e1f aeDispatchAppleEvent(AEDesc const*, AEDesc*, unsigned int, unsigned char*) + 381
                                    12 com.apple.AE 0x00007fff83d55c32 dispatchEventAndSendReply(AEDesc const*, AEDesc*) + 31
                                    13 com.apple.AE 0x00007fff83d55b36 aeProcessAppleEvent + 315
                                    14 com.apple.HIToolbox 0x00007fff877495f1 AEProcessAppleEvent + 56
                                    15 com.apple.AppKit 0x00007fff87d710f6 _DPSNextEvent + 1026
                                    16 com.apple.AppKit 0x00007fff87d708db -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 122
                                    17 com.apple.AppKit 0x00007fff87d649cc -[NSApplication run] + 553
                                    18 QtGui 0x0000000103572171 QDesktopWidget::resizeEvent(QResizeEvent*) + 3553
                                    19 QtGui 0x0000000103574070 QDesktopWidget::resizeEvent(QResizeEvent*) + 11488
                                    20 QtCore 0x000000010321c745 QCoreApplication::processEvents(QFlagsQEventLoop::ProcessEventsFlag) + 69
                                    21 QtGui 0x0000000103614aaf QWidgetPrivate::show_helper() + 639
                                    22 QtGui 0x0000000103614cff QWidget::setVisible(bool) + 511
                                    ....

                                    Last thing, I found when outputting application argc in exec function that it is not 1 as when I run it from QCreator, it is 24576!

                                    I hope someone had found a solution for this because I've been trying to sort it for a week

                                    thanks in advance

                                    1 Reply Last reply
                                    0
                                    • W Offline
                                      W Offline
                                      Wael
                                      wrote on last edited by
                                      #19

                                      Please ignore the above comment as it appeared to be the same issue, and the previous fix sorted it

                                      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