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. return 0; causes runtime error. Please help. ;_;
Forum Updated to NodeBB v4.3 + New Features

return 0; causes runtime error. Please help. ;_;

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 2 Posters 2.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.
  • T Offline
    T Offline
    Thynome
    wrote on last edited by Thynome
    #1

    Hey, I am having a really really dumb problem.. I wrote a console application (with project files set to not show a window) and the code itself works so far... But every time return 0; is called, the program closes - but gives me this very annoying error message...
    For my previous console applications I always used a.exec(); but it always requires a key to be pressed while it has the focus. But as I wrote before I'm not using a console window so I can't press the button.

    So guys... Can you please give me a way to close my program without an error message occuring or a key needing to be pressed? I sadly haven't found anything with the magical power of Google... Thanks in advance. :)

    In case it should be relevant, here's my .pro file...

    (There was a .pro file here.)

    ...and my code (simplified, because "the inside" already does what it's supposed to do).

    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv)
    
        ...
    
        return 0; or a.exec(); or what ever you suggest!
    }
    

    The solution can be found in the 8th post.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Looks strange indeed. What does a run through the debugger tells you ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Looks strange indeed. What does a run through the debugger tells you ?

        T Offline
        T Offline
        Thynome
        wrote on last edited by
        #3

        @SGaist said:

        Hi and welcome to devnet,

        Looks strange indeed. What does a run through the debugger tells you ?

        I don't really know how to use the debugger properly yet... But just klicking on the green triangle with the bug didn't make any difference. The error message occured as before and it said "terminate called without an active exception" just like it says on the picture. :/

        Thanks for the fast reply, though! I really appreciate that. :)

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Can you share your complete main function ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • T Offline
            T Offline
            Thynome
            wrote on last edited by Thynome
            #5

            TL; DR: Comments are German and the program is supposed to restart the computer and has certain control loops to abort the process if wished so.

            Yeah sure! :) My varible names are English, my comments are German tho... But I can tell you what my program roughly does. It's supposed to restart the computer every time it is executed (For testing purposes it'll restart in 166 minutes or so, so I have time to stop the process with cmd.) But I added a loop which lets me abort the process with Numpad0+Numpad1 if needed. In another thread runs a timer which will continue the program if the shortcuts aren't pressed in a certain amount of time. The length of the timer should also be dynamic - the first time it shall be 60 seconds (60000 ms) and create a file where the length of the next timer is written in (55000ms = 60000ms-5000ms). That's all for now. I'm currently working on the File part. :)

            When I made this thread this section didn't exist tho and everything worked fine (except the crash at the end!). And now with the addition of these lines obviously nothing has changed.

            But I don't wanna keep babbling all night long. ;) Here's my code:

            Edit: Finished the file part. This part should work now. (Updated the code here, too). Still having the problem with the error message, though.

            #include "Header.h"
            
            
            int main(int argc, char *argv[])
            {
                QApplication PermaRestart(argc, argv);
            
            /*Notice: I initially posted my main here. I removed it again after my problem has been solved.*/
            
                return 0;
            }
            
            1 Reply Last reply
            0
            • T Offline
              T Offline
              Thynome
              wrote on last edited by
              #6

              Still having the problem. Nobody able to offer a solution? :S

              1 Reply Last reply
              0
              • T Offline
                T Offline
                Thynome
                wrote on last edited by
                #7
                This post is deleted!
                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  Thynome
                  wrote on last edited by Thynome
                  #8

                  After a bit of expermimenting with already working console programs which use return 0;, I finally found the solution myself:

                  When using std::thread it seems to be a must to use the join() function somewhere after the start of the thread. I wasn't using join() for every of my threads because I already made it finish before calling return 0; with my program flow. And how I might experience: Not using join() causes an "unexpected terminate without active exception" message.

                  Confusingly I have never read about this absolute necessity of join() in all the C++ references I visited... They should add this as notice in my opinion. (Or I'm just blind, lol.)

                  Moderators can mark this as solved! ^.^

                  Thynome

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Please practice some patience, allow at least 24 hours before bumping your own thread. This forum is community driven and not all members live in the same timezone as you.

                    As for your problem, first: why are you using so much heap allocated objects ? Then: what does your threads do ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    T 1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Post crossed :D

                      Glad you found out :)

                      You can mark the thread solved yourself with the "Topic Tool" button :)

                      Happy coding !

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • SGaistS SGaist

                        Please practice some patience, allow at least 24 hours before bumping your own thread. This forum is community driven and not all members live in the same timezone as you.

                        As for your problem, first: why are you using so much heap allocated objects ? Then: what does your threads do ?

                        T Offline
                        T Offline
                        Thynome
                        wrote on last edited by Thynome
                        #11

                        @SGaist Sorry I bumped it but some random Korean guy made about 2 pages of spam threads and I was afraid to get forgetten. ;)

                        For the heap allocated objects: You're meaning the ones using new and delete don't you (Sorry, I started coding 6 - 7 months ago so I don't know all the professional words yet. ^^)? If you mean them, I'm using so many because in my code they completely replace my normal varibles. They just allow me more control over my program and (I know, it's absolutely not relevant in these scales.) better performance. I know about just using normal varibles and using call by reference with & if necessary but I personally find it confusing comparing to my dynamic pointers. :)

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          He got lucky today…

                          Don't worry about them.

                          Better performance ? Not necessarily: you deference these pointers most of the time so it's not really what's best for performance.

                          Since you're starting, take the time to study C++11, there are some pretty good books worth reading, especially if you're starting.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          T 1 Reply Last reply
                          0
                          • SGaistS SGaist

                            He got lucky today…

                            Don't worry about them.

                            Better performance ? Not necessarily: you deference these pointers most of the time so it's not really what's best for performance.

                            Since you're starting, take the time to study C++11, there are some pretty good books worth reading, especially if you're starting.

                            T Offline
                            T Offline
                            Thynome
                            wrote on last edited by
                            #13

                            @SGaist Can you recommend some in particular? I've already read some basic ones when I learned programming C from scratch but I'm interested in your opinion. If possible they shouldn't be too hard to read because my English is still not as good as my German. ^^

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              You can find some good references here and Effective Modern C++

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              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