Results 1 to 7 of 7

Thread: My software crashes

  1. #1
    Join Date
    May 2013
    Location
    Georgia,Tbilisi
    Posts
    32
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Question My software crashes

    Hi again.
    I was writing simple software,which have one big window. 2 Qpushbutton in this window. Parent is main window.
    when mouse cursor is approaching one of the button,button is moved at the other randomly got coordinate,and so on.

    I get .exe I get all neccessary .DLL files. in folder where exe is placed. Then I create folder: "platforms". There are "qwindows.dll".
    Everything seems all right but when I launch .exe file,suddenly it crashes.

    Then I created simple program, just big window. Did the same thing and then launched without any crashes.
    I think in code I have bug,which causes Segmentation fault.
    But I dont have any idea where are my mistake:

    .pro
    Qt Code:
    1. QT += widgets
    2.  
    3. HEADERS += \
    4. dialog.h
    5.  
    6. SOURCES += \
    7. dialog.cpp \
    8. main.cpp
    To copy to clipboard, switch view to plain text mode 

    Dialog.h
    Qt Code:
    1. #ifndef DIALOG_H
    2. #define DIALOG_H
    3.  
    4. #include <QWidget>
    5. #include <QPushButton>
    6. #include <QPoint>
    7.  
    8. class Dialog : public QWidget
    9. {
    10. Q_OBJECT
    11. public:
    12. explicit Dialog(QWidget *parent = 0);
    13.  
    14. signals:
    15. void PositionChanged();
    16.  
    17. public slots:
    18. void getNewPosition();
    19.  
    20. private:
    21. QPushButton *button1;
    22. QPushButton *button2;
    23. QPoint point1; //button1 position
    24. QPoint point2; //button2 position
    25. bool SecondButton;
    26. bool FirstButton;
    27.  
    28. protected:
    29. void mouseMoveEvent(QMouseEvent *);
    30.  
    31. };
    32.  
    33. #endif // DIALOG_H
    To copy to clipboard, switch view to plain text mode 

    Dialog.cpp
    Qt Code:
    1. #include "dialog.h"
    2. #include <QPushButton>
    3. #include <QWidgetItem>
    4. #include <QPoint>
    5. #include <QKeyEvent>
    6. Dialog::Dialog(QWidget *parent) :
    7. QWidget(parent)
    8. {
    9. //main window size
    10. setFixedSize(650,440);
    11.  
    12. //button1 related things
    13. button1 = new QPushButton(this);
    14. button1->setGeometry(QRect(200,200,75,23));
    15. button1->setText("one");
    16.  
    17. //button2 related things
    18. button2 = new QPushButton(this);
    19. button2->setGeometry(QRect(300,200,75,23));
    20. button2->setText("two");
    21. point1 = button1->pos();
    22. point2 = button2->pos();
    23.  
    24. connect(this,SIGNAL(PositionChanged()),this,SLOT(getNewPosition()));
    25.  
    26. setMouseTracking(true);
    27. SecondButton = true;
    28. FirstButton = true;
    29. }
    30. void Dialog::getNewPosition()
    31. {
    32. point1 = button1->pos();
    33. point2 = button2->pos();
    34. }
    35. void Dialog::mouseMoveEvent(QMouseEvent *event)
    36. {
    37. if(FirstButton && (( event->x() > point1.x() - 30 && event->x() < point1.x() + 105 )
    38. && (event->y() > point1.y() - 30 && event->y() < point1.y() + 54)))
    39. {
    40. //get random (x,y) coordinate
    41. int x = rand() % 550;
    42. int y = rand() % 400;
    43. button1->setGeometry(QRect(x,y,75,23));
    44. emit PositionChanged();
    45. SecondButton = false;
    46. }
    47. else if(SecondButton && ((event->y() > point2.y()-30 && event->y() < point2.y()+54)
    48. && ( event->x() > point2.x()-30 && event->x() < point2.x() + 105)))
    49. {
    50. //get random (x,y) coordinate
    51. int x = rand() % 550;
    52. int y = rand() % 400;
    53. button2->setGeometry(QRect(x,y,75,23));
    54. emit PositionChanged();
    55. FirstButton = false;
    56. }
    57. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "dialog.h"
    3.  
    4. int main(int argc,char *argv[])
    5. {
    6. QApplication app(argc,argv);
    7.  
    8.  
    9. Dialog dg;
    10. dg.show();
    11.  
    12. return app.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 


    Any Ideas?

    P.S sorry for my English. It isn't my native language

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: My software crashes

    Everything seems all right but when I launch .exe file,suddenly it crashes.
    What is the error shown?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    May 2013
    Location
    Georgia,Tbilisi
    Posts
    32
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: My software crashes

    Quote Originally Posted by Santosh Reddy View Post
    What is the error shown?
    Capture.JPG

    Then,when I look at event log:

    Capture2.JPG

    I'm working on the code and i think problem is this:
    Qt Code:
    1. button1 = new QPushButton(this);
    To copy to clipboard, switch view to plain text mode 

    When I remove "this" parent. Everything works just fine
    but without "this" I can't add buttons to mainWindow.


    Added after 1 21 minutes:


    I'have just commented this line:
    Qt Code:
    1. button1->setText("one");
    To copy to clipboard, switch view to plain text mode 

    and it works! It doesn't crash
    But Can't set text on a button
    Last edited by Higgs; 9th January 2014 at 18:12.

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: My software crashes

    For me (Microsoft Visual C++ 2008 32 bit, Qt 4.8.5) all is working without problems. What is your compiler ?

  5. #5
    Join Date
    May 2013
    Location
    Georgia,Tbilisi
    Posts
    32
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: My software crashes

    Quote Originally Posted by Lesiok View Post
    For me (Microsoft Visual C++ 2008 32 bit, Qt 4.8.5) all is working without problems. What is your compiler ?
    Microsoft Visual C++ 2012 32 Bit.
    Qt 5.1.1

    P.S I take .exe from Release folder.

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: My software crashes

    Do you have multiple versions of Qt on your machine?
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  7. #7
    Join Date
    May 2013
    Location
    Georgia,Tbilisi
    Posts
    32
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: My software crashes

    Quote Originally Posted by Santosh Reddy View Post
    Do you have multiple versions of Qt on your machine?
    I think no. But At first I had many versions installed on my computer. First 4.x then 5.1 an then also 5.1(uninstaled and then installed again)
    now,I have Qt 5.1.1. Seems I haven't other version of Qt.

Similar Threads

  1. qInitResources_mimetypes() crashes
    By ComServant in forum Qt Programming
    Replies: 2
    Last Post: 16th May 2014, 20:36
  2. Replies: 0
    Last Post: 11th January 2013, 11:21
  3. What's This crashes on Mac OS X?
    By ypeels in forum Qt Programming
    Replies: 1
    Last Post: 31st October 2012, 15:33
  4. Application crashes when it has a particular name
    By hunsrus in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2010, 20:50
  5. app crashes again
    By sophister in forum Qt Programming
    Replies: 7
    Last Post: 15th June 2009, 10:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.