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. sometimes qt was ended forcefully, weird.

sometimes qt was ended forcefully, weird.

Scheduled Pinned Locked Moved Unsolved General and Desktop
39 Posts 6 Posters 4.1k 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.
  • C Offline
    C Offline
    circle
    wrote on last edited by
    #1

    hi,
    i am using qt 5.15.1 and qtcreator 4.13.2, when i press CTRL+R to run the program, sometimes (50% possibility) it was ended forcefully (nothing else is changed by me), but not with the DEBUG mode(F5). i have located it was crashed in the following code snippets,

    QFileInfo file(QCoreApplication::applicationFilePath());
    if (some condition)
    {
    QMessageBox::information(this, "title", QString("%1").arg(file.size()));
    }

    if i run the program in the console, it prints the following things,
    *** Error in './FC': fress(): invalid pointer: 0x............ ***
    you know what, based on this, i modified the code as below,
    QFileInfo file(“~/qt/.....”);
    if (some condition)
    {
    QMessageBox::information(this, "title", QString("%1").arg(file.size()));
    }
    and it will never be crashed here but later somewhether in the same block {}. (trying to contrust an instance of an invalid type, type id:1061)

    anothing weird is, this version is modified from yesterday's version. they are same but the newer version has some more function somewhere after the crash position, but old version never crash.

    it's a big project so it's difficult to post the whole code. pls anybody could give me some advice or opinion?

    thanks,
    Circle

    JonBJ Pl45m4P 2 Replies Last reply
    0
    • C circle

      hi,
      i am using qt 5.15.1 and qtcreator 4.13.2, when i press CTRL+R to run the program, sometimes (50% possibility) it was ended forcefully (nothing else is changed by me), but not with the DEBUG mode(F5). i have located it was crashed in the following code snippets,

      QFileInfo file(QCoreApplication::applicationFilePath());
      if (some condition)
      {
      QMessageBox::information(this, "title", QString("%1").arg(file.size()));
      }

      if i run the program in the console, it prints the following things,
      *** Error in './FC': fress(): invalid pointer: 0x............ ***
      you know what, based on this, i modified the code as below,
      QFileInfo file(“~/qt/.....”);
      if (some condition)
      {
      QMessageBox::information(this, "title", QString("%1").arg(file.size()));
      }
      and it will never be crashed here but later somewhether in the same block {}. (trying to contrust an instance of an invalid type, type id:1061)

      anothing weird is, this version is modified from yesterday's version. they are same but the newer version has some more function somewhere after the crash position, but old version never crash.

      it's a big project so it's difficult to post the whole code. pls anybody could give me some advice or opinion?

      thanks,
      Circle

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

      @circle said in sometimes qt was ended forcefully, weird.:

      *** Error in './FC': fress(): invalid pointer: 0x............ ***

      So fress() is a method of yours?

      You may be able to use a core dump from not-running-in-debugger to get information about where the crash occurred, e.g. gdb executable core.

      You can Google for qt trying to construct an instance of an invalid type for possibilities about what might be at issue (e.g. possibly a QVariant).

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

        free() is not mine, i guess it was the temp QString object by QCoreApplication::applicationFilePath().
        When I debug the program by press F5 (via gdb), it never crash. so do you think core dump with gdb might help? im asking because i am new to qt, linux and gdb.

        in addition, about the invalid type, i googled before but i have no idea how to locate the problem, the code snippet is as below,
        ui->statusbar->addwidget(ui->line1);
        ui->statusbar->addwidget(ui->label1);
        ...

        JonBJ 1 Reply Last reply
        0
        • C circle

          free() is not mine, i guess it was the temp QString object by QCoreApplication::applicationFilePath().
          When I debug the program by press F5 (via gdb), it never crash. so do you think core dump with gdb might help? im asking because i am new to qt, linux and gdb.

          in addition, about the invalid type, i googled before but i have no idea how to locate the problem, the code snippet is as below,
          ui->statusbar->addwidget(ui->line1);
          ui->statusbar->addwidget(ui->label1);
          ...

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

          @circle
          But your post does not mention free(). I quoted what you wrote:

          *** Error in './FC': fress(): invalid pointer: 0x............ ***

          Please, please don't tell me you chose to type in the message without copy/pasting it, and on top of that got it wrong? You wouldn't do that, would you, because it's not fair on those trying to help you if you just give out wrong information, and for my own part I don't help people if they do that.

          C 1 Reply Last reply
          2
          • C circle

            hi,
            i am using qt 5.15.1 and qtcreator 4.13.2, when i press CTRL+R to run the program, sometimes (50% possibility) it was ended forcefully (nothing else is changed by me), but not with the DEBUG mode(F5). i have located it was crashed in the following code snippets,

            QFileInfo file(QCoreApplication::applicationFilePath());
            if (some condition)
            {
            QMessageBox::information(this, "title", QString("%1").arg(file.size()));
            }

            if i run the program in the console, it prints the following things,
            *** Error in './FC': fress(): invalid pointer: 0x............ ***
            you know what, based on this, i modified the code as below,
            QFileInfo file(“~/qt/.....”);
            if (some condition)
            {
            QMessageBox::information(this, "title", QString("%1").arg(file.size()));
            }
            and it will never be crashed here but later somewhether in the same block {}. (trying to contrust an instance of an invalid type, type id:1061)

            anothing weird is, this version is modified from yesterday's version. they are same but the newer version has some more function somewhere after the crash position, but old version never crash.

            it's a big project so it's difficult to post the whole code. pls anybody could give me some advice or opinion?

            thanks,
            Circle

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #5

            @circle

            Do you try to delete some object twice?


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

            ~E. W. Dijkstra

            C 1 Reply Last reply
            1
            • JonBJ JonB

              @circle
              But your post does not mention free(). I quoted what you wrote:

              *** Error in './FC': fress(): invalid pointer: 0x............ ***

              Please, please don't tell me you chose to type in the message without copy/pasting it, and on top of that got it wrong? You wouldn't do that, would you, because it's not fair on those trying to help you if you just give out wrong information, and for my own part I don't help people if they do that.

              C Offline
              C Offline
              circle
              wrote on last edited by
              #6

              @JonB
              i am sorry, that was what i did. now i connect the local machine to internet so i am going to post more code here,

              MainWindow::MainWindow(QWidget *parent)
                  : QMainWindow(parent)
                  , ui(new Ui::MainWindow)
              {
                  ui->setupUi(this);
                  showFullScreen();
              
                  ui->dockWidget->setWidget(ui->tableWidget);
              
                  ui->line1->hide();
              }
              
              
              void MainWindow::resizeEvent(QResizeEvent *event)
              {
                  QMainWindow::resizeEvent(event);
              
                  // Your code here.
                  static bool bOnlyOnce = true;
                  if (bOnlyOnce && isVisible())
                  {
                      //doing some initialization here
              
                      QFileInfo fileInfo(QCoreApplication::applicationFilePath()); 
                      if ()
                          QMessageBox::information(this, "title", QString("%1").arg(fileInfo.size()));
                  
                      //doing more staff, basically ui layout work
              
                      ui->statusbar->addWidget(ui->lable1, 40); 
                  }
              }
              
              

              now the QMessageBox line would crash sometimes(qtcreator says the process was ended forcefully), and if i comment out this line, the ui->statusbar line sometimes would report "Trying to construct an instance of an invalid type, type id: 1061" and the process was ended forcefully.
              i haven't found any rules about "sometimes", sometimes it will crash several times continuously when i press CTRL+R, but sometimes the program works fine.

              1 Reply Last reply
              0
              • Pl45m4P Pl45m4

                @circle

                Do you try to delete some object twice?

                C Offline
                C Offline
                circle
                wrote on last edited by
                #7

                @Pl45m4
                thanks but no. the weird thing is it's working sometimes without changing anything apparently.

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

                  Hi,

                  Why are you doing that layouting logic that should run only once in your resize event ?

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

                  C 1 Reply Last reply
                  2
                  • SGaistS SGaist

                    Hi,

                    Why are you doing that layouting logic that should run only once in your resize event ?

                    C Offline
                    C Offline
                    circle
                    wrote on last edited by
                    #9

                    @SGaist
                    thanks, the gui is supposed to be fullscreen all the time,and some initialization work should be done only once, as well as the layout work which is based on fullscreen.

                    anyway, i just found the problem of ui->statusbar line might be related to stylesheet. the original stylesheet set in the property window is as below,
                    QStatusBar{border-top: 1px outset grey;}
                    QStatusBar::item{border: 0px}
                    if i clear this setting, it seems it's not reporting the error(trying to Trying to construct an instance of an invalid type) anymore.
                    if i change the stylesheet to some back-ground color, it might be crash again, but not with the error (trying to Trying to construct an instance of an invalid type) anymore.
                    even i set the stylesheet in the mainwidow.cpp code, it also might be crashed sometimes.

                    actually, i still don't believe it's the root reason, one reason is i don't see anything is wrong with the stylesheet, the other reason it never crash in the old backup version.

                    i googled a lot but i haven't found anything helpful.

                    i have stuck into here for a long time, based on the information i just mentioned, do you have any further advice?

                    thank you all very much for your time and help.

                    J.HilkJ 1 Reply Last reply
                    0
                    • C circle

                      @SGaist
                      thanks, the gui is supposed to be fullscreen all the time,and some initialization work should be done only once, as well as the layout work which is based on fullscreen.

                      anyway, i just found the problem of ui->statusbar line might be related to stylesheet. the original stylesheet set in the property window is as below,
                      QStatusBar{border-top: 1px outset grey;}
                      QStatusBar::item{border: 0px}
                      if i clear this setting, it seems it's not reporting the error(trying to Trying to construct an instance of an invalid type) anymore.
                      if i change the stylesheet to some back-ground color, it might be crash again, but not with the error (trying to Trying to construct an instance of an invalid type) anymore.
                      even i set the stylesheet in the mainwidow.cpp code, it also might be crashed sometimes.

                      actually, i still don't believe it's the root reason, one reason is i don't see anything is wrong with the stylesheet, the other reason it never crash in the old backup version.

                      i googled a lot but i haven't found anything helpful.

                      i have stuck into here for a long time, based on the information i just mentioned, do you have any further advice?

                      thank you all very much for your time and help.

                      J.HilkJ Online
                      J.HilkJ Online
                      J.Hilk
                      Moderators
                      wrote on last edited by
                      #10

                      @circle are you sure you set bOnlyOnce to false anywhere ? It's not in your code.

                      resize events may be queued up already, when its first called, and QmessageBox will spin its own event loop that could be the problem here


                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      C 1 Reply Last reply
                      1
                      • J.HilkJ J.Hilk

                        @circle are you sure you set bOnlyOnce to false anywhere ? It's not in your code.

                        resize events may be queued up already, when its first called, and QmessageBox will spin its own event loop that could be the problem here

                        C Offline
                        C Offline
                        circle
                        wrote on last edited by
                        #11

                        @J-Hilk
                        sorry forget to post that line, the first thing in the if(bOnlyOnce) block is to set bOnlyOnce = false;

                        i understand resize events may be queued, and QMessageBox has its own event loop, but sorry i am not very aware of what you said, how it affect?

                        from my debug log, it will go to the resize function block after showFullscreen() in the constructor, but it's not visible yet, so after back to the constructor, the system will call resize function again to do the initialization work.

                        In addition, when i press F5 to debug the program, i never reproduce the problem. and i can't reproduce the problem with the old backup version, and they are same in the constructor and resize function block.

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

                          Can you explain what kind of logic is required to be run in the resize event ?

                          Typically I do not see why you would need to add a widget there.

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

                          C 1 Reply Last reply
                          2
                          • SGaistS SGaist

                            Can you explain what kind of logic is required to be run in the resize event ?

                            Typically I do not see why you would need to add a widget there.

                            C Offline
                            C Offline
                            circle
                            wrote on last edited by
                            #13

                            @SGaist
                            thanks for your time. my app is fullscreen always, and the main reason i do the initialization work in the resize event is, i need to know the size of the fullscreen, as a lot of drawing is based on this size. Most of the drawing is done in the memory, while the small part is done in paintEvent.
                            where do you think i should do these things? showEvent?

                            Pl45m4P 1 Reply Last reply
                            0
                            • C circle

                              @SGaist
                              thanks for your time. my app is fullscreen always, and the main reason i do the initialization work in the resize event is, i need to know the size of the fullscreen, as a lot of drawing is based on this size. Most of the drawing is done in the memory, while the small part is done in paintEvent.
                              where do you think i should do these things? showEvent?

                              Pl45m4P Offline
                              Pl45m4P Offline
                              Pl45m4
                              wrote on last edited by Pl45m4
                              #14

                              @circle said in sometimes qt was ended forcefully, weird.:

                              where do you think i should do these things?

                              You can get the size (geometry) of your widget anywhere, without calling the stuff every time you resize.

                              If you want to do something just once, consider doing it inside your c'tor or use the showEvent, when you need the actual size.
                              (Your widget's size in c'tor and showEvent will / may be different, because of layouts)


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

                              ~E. W. Dijkstra

                              C 1 Reply Last reply
                              0
                              • Pl45m4P Pl45m4

                                @circle said in sometimes qt was ended forcefully, weird.:

                                where do you think i should do these things?

                                You can get the size (geometry) of your widget anywhere, without calling the stuff every time you resize.

                                If you want to do something just once, consider doing it inside your c'tor or use the showEvent, when you need the actual size.
                                (Your widget's size in c'tor and showEvent will / may be different, because of layouts)

                                C Offline
                                C Offline
                                circle
                                wrote on last edited by
                                #15

                                @Pl45m4 said in sometimes qt was ended forcefully, weird.:

                                c'tor

                                thanks, i tried to get the real fullscreen's size in the c'tor or in the showEvent, but the size was wrong. that's why i put those work in the resizeEvent and isVisible() block.

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

                                  @circle said in sometimes qt was ended forcefully, weird.:

                                  tried to get the real fullscreen's size in the c'tor

                                  QScreen doesn't work differently if it is called in the ctor or anywhere else.

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

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

                                    Depending on what you need, I would rather go with changeEvent and check the QEvent::WindowStateChange event. You will know there when the window is fullscreen.

                                    But again, doing stuff that depends on the specifics of being fullscreen is a bit surprising. Painting is usually done so that it does not directly depend on one specific size because even if fullscreen you may have different sizes.

                                    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
                                    1
                                    • Christian EhrlicherC Christian Ehrlicher

                                      @circle said in sometimes qt was ended forcefully, weird.:

                                      tried to get the real fullscreen's size in the c'tor

                                      QScreen doesn't work differently if it is called in the ctor or anywhere else.

                                      C Offline
                                      C Offline
                                      circle
                                      wrote on last edited by
                                      #18

                                      @Christian-Ehrlicher
                                      more precisely, what i need is the size of centralwidget when it's fullscreen. so i just use the width() and hegith() to obtain those when it's fullscreen.
                                      i didn't use QScreen, should i?

                                      @SGaist
                                      there may be different ways to get the size, but i still don't have a clue why it produce such an error. it seems have nothing to do with the error, and why sometimes it's working, sometimes not.

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

                                        @circle said in sometimes qt was ended forcefully, weird.:

                                        i didn't use QScreen, should i?

                                        I suggest you to use it so I would say it's worth a try reading the documentation, isn't it?

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

                                        1 Reply Last reply
                                        0
                                        • C circle

                                          @Christian-Ehrlicher
                                          more precisely, what i need is the size of centralwidget when it's fullscreen. so i just use the width() and hegith() to obtain those when it's fullscreen.
                                          i didn't use QScreen, should i?

                                          @SGaist
                                          there may be different ways to get the size, but i still don't have a clue why it produce such an error. it seems have nothing to do with the error, and why sometimes it's working, sometimes not.

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

                                          @circle said in sometimes qt was ended forcefully, weird.:

                                          more precisely, what i need is the size of centralwidget when it's fullscreen.

                                          Then it doesn't sound like you should be looking at QScreen at all.

                                          thanks, i tried to get the real fullscreen's size in the c'tor or in the showEvent,

                                          To get a size of widget (not the full screen, which you shouldn't be interested in) correctly it needs to be shown. If you call it too early, you get rubbish. Constructor is not the place. If in a showEvent(), IIRC you should call the base showEvent() before you try to read the size.

                                          C 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