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. Application crashes when mouse moves
QtWS25 Last Chance

Application crashes when mouse moves

Scheduled Pinned Locked Moved General and Desktop
22 Posts 2 Posters 8.3k 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
    SherifOmran
    wrote on 14 Feb 2014, 07:09 last edited by
    #1

    Hello guys,

    i am writing an application that trains letter typing. Upon writing a wrong letter, it's color is changed into red and for a correct letter its color is made green .. There is a timer in the window to calculate the typing speed.

    The application crashes when i move the mouse over the text area and tries to close the window .. I disconnect the timer before i close the window ..

    -> Unfortunately i don't how to use valgrind .. I installed it but it seems not correctly working ..
    -> is there a way to trun garbage collection to ON?

    Any idea how can i debug this point .. Before it crashes, it shows these lines?

    0 QtGui 0x0000000100995ce0 QApplication::desktop() + 32
    1 QtGui 0x0000000100946f6b flipPoint(CGPoint const&) + 27
    2 QtGui 0x0000000100949ded qt_mac_getTargetForMouseEvent(NSEvent*, QEvent::Type, QPoint&, QPoint&, QWidget*, QWidget**) + 205
    3 QtGui 0x000000010094a77a qt_mac_handleMouseEvent(NSEvent*, QEvent::Type, Qt::MouseButton,

    any help is appreciated ..

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 14 Feb 2014, 07:25 last edited by
      #2

      Hi,

      Can you run your application through the debugger ? That should already give you some information about what happens.

      Also, what version of Qt/OS X are you using ?

      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
      • S Offline
        S Offline
        SherifOmran
        wrote on 14 Feb 2014, 07:31 last edited by
        #3

        When i run through the debugger it says the inferior stopped because
        it received a signal from the os
        EXC_bad_access
        could not access memory

        Mac os: 10.7.5
        QT creator : 2.4.1
        based on 4.7.6
        build on jan 25 12

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 14 Feb 2014, 18:30 last edited by
          #4

          You should have a backtrace of what is happening when the crash occurred, what is it ?

          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
          • S Offline
            S Offline
            SherifOmran
            wrote on 14 Feb 2014, 20:47 last edited by
            #5

            the object window -> creates another highlighting object
            at some instance which i don't know when (may be when writing in high speed), the highlighting object is called, it tries to make the paint event but at the same time, there might be other events (i don't know what is it) and they crash together ..

            It seems that some object is not correctly deleted ... i don't know how to find it ..

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SherifOmran
              wrote on 14 Feb 2014, 20:55 last edited by
              #6

              I installed valgrind in /usr/bin/ i see in it a file called vgrind
              but when i do in QT - Analyze - Valgrind analyze memory or function i get

              Analyzing memory of /login
              ** Error: "valgrind" could not be started: No such file or directory **
              ** Analyzing finished **

              I installed valgrind this way

              cd /Volumes/Macintosh\ HD/Users/so/Downloads/valgrind-3.9.0
              ./configure --prefix=/usr/bin
              make
              sudo make install

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 14 Feb 2014, 21:36 last edited by
                #7

                Try giving the full path in Qt Creator.

                Are you using delete on these objects or call deleteLater ?

                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
                • S Offline
                  S Offline
                  SherifOmran
                  wrote on 15 Feb 2014, 06:41 last edited by
                  #8

                  yes i use delete after the object finishes ..
                  I managed to install valgrind correctly and now i have the analyze-memory and function working .. which one should i use to find what hangs up while deleting the object?

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 15 Feb 2014, 21:19 last edited by
                    #9

                    If these are QObject derived classes you should rather use deleteLater

                    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
                    • S Offline
                      S Offline
                      SherifOmran
                      wrote on 17 Feb 2014, 20:03 last edited by
                      #10

                      Lets try to find the mistake because i am struggling since 2 days and don't see it ..

                      Header file
                      @
                      #ifndef PRACTISING_H
                      #define PRACTISING_H

                      #include <QKeyEvent>
                      #include <QWidget>

                      #include "highlighter.h"
                      #include "typingtutormain.h" //1
                      #include "keygramform.h"

                      #include <QBitArray>
                      #include "keyboardmap.h"
                      #include "practisehandwin.h"
                      //#include "qgarbagecollector.h"

                      namespace Ui {
                      class practising;

                      }

                      class practising : public QDialog
                      {
                      Q_OBJECT

                      public:
                      practising(bool traintestmode, int mintext, int maxtext, QWidget *parent);
                      ~practising();
                      TypingTutorMain *mainparentform; //2
                      void handwindowcloseevent();
                      inline void setWindowPositionAndSize(const QRect& fg) {resize(fg.size()); move(fg.topLeft());}
                      inline QRect windowPositionAndSize() const { return QRect(pos(), size()); }

                      private slots:
                      void on_previous_Btn_clicked();
                      void on_next_Btn_clicked();
                      void on_start_Btn__clicked();
                      void on_stop_Btn_clicked();
                      void timercount(void);
                      void lostfocus();

                      private:
                      Ui::practising *ui;
                      QPointer <Highlighter> highlighter;
                      QPointer <KeyBoardMap> kbmap;
                      QPointer <QDesktopWidget> d; // for window size
                      QTime PracticeTimer; // Timer in the practise (Stop watch)
                      QPointer <QTimer> PractiseTimerFire; // Timer fireing each 1 sec to count the stop watch
                      // QScopedPointer <QTimer> PractiseTimerFire;
                      QPointer <practisehandwin> handpop;
                      QPointer <QScrollBar> sb;

                      };

                      #endif // PRACTISING_H

                      @

                      Highlighter class
                      @
                      class Highlighter : public QSyntaxHighlighter
                      {
                      Q_OBJECT
                      public:
                      @

                      keyboard map class
                      @

                      class KeyBoardMap : public QDialog
                      {
                      Q_OBJECT

                      public:

                      @

                      @
                      practising::~practising()
                      {

                      qDebug() << "practise done return";
                      done(1);
                      qDebug() << "practising::~practising";
                      
                      //delete ui; // it will be deleted there in the calling form
                      

                      }

                      void practising::closeEvent(QCloseEvent *event)
                      {
                      qDebug()<< "practising::closeEvent";

                      PractiseTimerFire->stop();
                      QObject::disconnect(PractiseTimerFire,0);
                      
                      qDebug()<<"to delete highlighter";
                      delete highlighter;
                      
                      qDebug() << "to delete keyboard map ";
                      delete kbmap;
                      
                      qDebug() << "to delete timer";
                      delete PractiseTimerFire;
                      
                      qDebug() << "to delete handpop";
                      delete handpop;
                      
                      qDebug() << " delete scroll bar";
                      delete sb;
                      
                      qDebug() << " ------------";
                      
                      
                      if (handwindowenabled==true) //if handwindow is open
                      {
                         qDebug() << "practising:close-1";
                         //handpop.data()->close();
                         //QMetaObject::invokeMethod(handpop, "close", Qt::QueuedConnection);//important line
                         //delete handpop;
                         //handpop.data()->deleteLater();
                      }
                      this->mainparentform->show();
                      //event->accept();
                      
                      qDebug() << "closesevent - first part pass" << handpop.isNull();
                      
                      
                      
                      delete d;
                      //delete inst_speed;
                      //delete inst_speed_correct;
                      //delete inst_speed_correct_diff;
                      //delete inst_speed_timepassd;
                      
                      //Practise_AddToDataBase(); // Add data to dB
                      
                      qDebug() << "closever 2";
                      //Q_UNUSED(event); //unreferenced formal parameter
                      qDebug() << "closever 3";
                      quitpractise = true;
                      
                      //delete ui;
                      

                      }

                      @

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SherifOmran
                        wrote on 17 Feb 2014, 20:22 last edited by
                        #11

                        should QSyntaxHighlighter be also treated with deletelater?

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 17 Feb 2014, 21:27 last edited by
                          #12

                          You are doing things in a pretty unusual way.

                          Why use closeEvent to destroy everything ? In your case the destructor is there for that.

                          Why are you using QPointer for everything ? It's not it's purpose

                          Also, you are probably deleting objects that have parent that would be destroyed automatically when "practicing" is destroyed.

                          Also, why windowPositionAndSize ? look at QWidget::geometry()

                          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
                          • S Offline
                            S Offline
                            SherifOmran
                            wrote on 21 Feb 2014, 17:06 last edited by
                            #13

                            I am still learning QT ... I will take the pointer one by one for me to learn ..
                            First, lets take the QTimer, i want to get initialized when i press on start button
                            @
                            QTimer *PractiseTimerFire = new QTimer(this);
                            connect(PractiseTimerFire, SIGNAL(timeout()),this, SLOT(timercount()));
                            PractiseTimerFire->start(1000);
                            @

                            I need to disable it when i click on the Stop button, but it is then not defined .. I need to cast it but don't know how .. Could you please help me?

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              SherifOmran
                              wrote on 21 Feb 2014, 17:57 last edited by
                              #14

                              I use the widget::close event because the widget is a second window called from a first window , and i want the first window to be visible back, so i made a parent child mechanism ..

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                SherifOmran
                                wrote on 21 Feb 2014, 18:51 last edited by
                                #15

                                I have it now solved ... I sent a message from the child to a parent method called (closepractise) in order to close the child .. it worked ..

                                Vielen Dank .. Allerdings ich brauche Unterstützung in der Zukunft

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 21 Feb 2014, 22:06 last edited by
                                  #16

                                  Depending on how you create the dialog you should not even need that

                                  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
                                  • S Offline
                                    S Offline
                                    SherifOmran
                                    wrote on 22 Feb 2014, 15:25 last edited by
                                    #17

                                    I want to ask a simple question because i don't know its answer, Please ..

                                    lets says in mainwindow, i create a new window called A
                                    QWidget A=new QWidget(0)

                                    Inside A, i want to create a new window that is located beside A and it should be a child ..
                                    If i say
                                    QWidget B=new QWidget (A) -> it will be inside window A
                                    so i must call it
                                    QWidget B=new QWidget (0) -> to make a new window
                                    but then B is not a child of A and will not close if A is closed ..

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on 22 Feb 2014, 21:15 last edited by
                                      #18

                                      Then it all depends on how you use that window. Is B a member of A ? If so you can e.g. reimplement closeEvent and also close B in there. If not create a signal that you emit from A when it's closing and connect it to B's close slot

                                      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
                                      • S Offline
                                        S Offline
                                        SherifOmran
                                        wrote on 23 Feb 2014, 10:42 last edited by
                                        #19

                                        What you mean by B member of A? B is a window, A is also a window
                                        I imlemented your signalling idea but i want ask : I used to do it the following way, is it correct?

                                        @
                                        qPointer <handpop> qWidget;
                                        QWidget handpop = new QWidget (0);

                                        if (!handpop.isNull())
                                        {
                                            handpop.data()->close();
                                        }
                                        delete handpop;
                                        

                                        @

                                        1 Reply Last reply
                                        0
                                        • S Offline
                                          S Offline
                                          SherifOmran
                                          wrote on 23 Feb 2014, 11:32 last edited by
                                          #20

                                          I tested the signal method but it is not good, it breaks
                                          in practising i create a handwindow
                                          @
                                          handpop = new practisehandwin(0);
                                          connect(this,SIGNAL(destroyed()),handpop.data(),SLOT(close()));
                                          @

                                          I tested also with by emitting a signal to the handpop to close it self ..

                                          1 Reply Last reply
                                          0

                                          8/22

                                          15 Feb 2014, 06:41

                                          14 unread
                                          • Login

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