Results 1 to 20 of 21

Thread: QT VS C++ 2005, QPushButton NOT FIRING!!!!!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default QT VS C++ 2005, QPushButton NOT FIRING!!!!!

    I am new to qt and I am trying to build a new project with QT. I have a nice GUI built in my login form and everything is compiling great until I try to connect my button to a function using signals and slots.

    First I tried to use the QT editor. I would use the slots and signals editor and I couldn't figure out how to get it to my functions in my .cpp then I tried to do it outside of the editor by adding the connect button to my cpp and my header. I can get it to compile but i get an error saying "irst-chance exception at 0x670e98d8 in TheWGE.exe: 0xC0000005: Access violation reading location 0xffffffff.
    Unhandled exception at 0x670e98d8 in TheWGE.exe: 0xC0000005: Access violation reading location 0xffffffff. BREAK OR CONTINUE"

    this is my thewge.cpp

    Qt Code:
    1. #include "thewge.h"
    2. #include <QtGui/QApplication>
    3. #include <QSignalMapper>
    4. #include <QPushButton>
    5.  
    6. TheWGE::TheWGE(QWidget *parent, Qt::WFlags flags)
    7. : QMainWindow(parent, flags)
    8. {
    9.  
    10. ui.setupUi(this);
    11.  
    12. QObject::connect(LoginBtn, SIGNAL(clicked()), this, SLOT(accept()));
    13.  
    14. }
    15.  
    16. TheWGE::~TheWGE()
    17. {
    18. //delete usrLineEdit;
    19. //delete pwdLineEdit;
    20. }
    21.  
    22. void TheWGE::readSettings()
    23. {
    24. //Set Focus to the right place
    25.  
    26. /* if (ui.usrLineEdit->text().trimmed().isEmpty() ) {
    27.   ui.usrLineEdit->setFocus();
    28.   } else {
    29.   ui.pwdLineEdit->setFocus();
    30.   } */
    31.  
    32. }
    33.  
    34. void TheWGE::accept()
    35. {
    36. //readSettings();
    37. }
    To copy to clipboard, switch view to plain text mode 


    my thewge.h

    Qt Code:
    1. #ifndef THEWGE_H
    2. #define THEWGE_H
    3.  
    4. #include <QtGui/QMainWindow>
    5. #include "ui_thewge.h"
    6. #include <QPixmap>
    7. class TheWGE : public QMainWindow
    8. {
    9. Q_OBJECT
    10.  
    11.  
    12. public:
    13. TheWGE(QWidget *parent = 0, Qt::WFlags flags = 0);
    14. ~TheWGE();
    15.  
    16. private:
    17. Ui::TheWGEClass ui;
    18. QLineEdit* usrLineEdit;
    19. QLineEdit* pwdLineEdit;
    20. QPushButton* LoginBtn;
    21.  
    22. public slots:
    23.  
    24. void accept();
    25. void readSettings();
    26.  
    27. //QObject::connect(LoginBtn, SIGNAL(clicked()), thewge, SLOT(accept()));
    28.  
    29. };
    30.  
    31. #endif // THEWGE_H
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT VS C++ 2005, QPushButton NOT FIRING!!!!!

    First: No need to SHOUT

    Second, usrLineEdit, pwdLineEdit & LoginBtn don't seem to be initialised, so you will get an access violation.

    Third, why not connect to controls in the ui class?

  3. #3
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT VS C++ 2005, QPushButton NOT FIRING!!!!!

    Haha sorry about the yelling :P

    I think I have them initialized, I am in MSVS 2005 and I have the qt Addin. I will show my .ui and the header it generates, that header is where I think everything is being initailized.

    xml Code:
    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <ui version="4.0">
    3. <class>TheWGEClass</class>
    4. <widget class="QMainWindow" name="TheWGEClass">
    5. <property name="geometry">
    6. <rect>
    7. <x>0</x>
    8. <y>0</y>
    9. <width>649</width>
    10. <height>348</height>
    11. </rect>
    12. </property>
    13. <property name="sizePolicy">
    14. <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
    15. <horstretch>0</horstretch>
    16. <verstretch>0</verstretch>
    17. </sizepolicy>
    18. </property>
    19. <property name="minimumSize">
    20. <size>
    21. <width>649</width>
    22. <height>348</height>
    23. </size>
    24. </property>
    25. <property name="maximumSize">
    26. <size>
    27. <width>649</width>
    28. <height>348</height>
    29. </size>
    30. </property>
    31. <property name="windowTitle">
    32. <string>TheWGE Anti-Cheat Client</string>
    33. </property>
    34. <property name="styleSheet">
    35. <string notr="true">background-image: url(:/TheWGE/gamers.PNG)</string>
    36. </property>
    37. <widget class="QWidget" name="centralWidget">
    38. <widget class="QLineEdit" name="usrLineEdit">
    39. <property name="geometry">
    40. <rect>
    41. <x>270</x>
    42. <y>200</y>
    43. <width>170</width>
    44. <height>29</height>
    45. </rect>
    46. </property>
    47. <property name="maximumSize">
    48. <size>
    49. <width>170</width>
    50. <height>29</height>
    51. </size>
    52. </property>
    53. <property name="styleSheet">
    54. <string notr="true">background-image: url(:/TheWGE/textbox.PNG);
    55. color: rgb(255, 255, 255);</string>
    56. </property>
    57. <property name="maxLength">
    58. <number>40</number>
    59. </property>
    60. <property name="frame">
    61. <bool>false</bool>
    62. </property>
    63. </widget>
    64. <widget class="QLineEdit" name="pwdLineEdit">
    65. <property name="geometry">
    66. <rect>
    67. <x>270</x>
    68. <y>230</y>
    69. <width>170</width>
    70. <height>29</height>
    71. </rect>
    72. </property>
    73. <property name="maximumSize">
    74. <size>
    75. <width>170</width>
    76. <height>29</height>
    77. </size>
    78. </property>
    79. <property name="styleSheet">
    80. <string notr="true">background-image: url(:/TheWGE/textbox.PNG);
    81. color: rgb(255, 255, 255);</string>
    82. </property>
    83. <property name="frame">
    84. <bool>false</bool>
    85. </property>
    86. </widget>
    87. <widget class="QPushButton" name="LoginBtn">
    88. <property name="geometry">
    89. <rect>
    90. <x>350</x>
    91. <y>270</y>
    92. <width>90</width>
    93. <height>31</height>
    94. </rect>
    95. </property>
    96. <property name="styleSheet">
    97. <string notr="true">background-image: url(:/TheWGE/login.PNG)</string>
    98. </property>
    99. <property name="text">
    100. <string/>
    101. </property>
    102. <property name="flat">
    103. <bool>true</bool>
    104. </property>
    105. </widget>
    106. </widget>
    107. </widget>
    108. <layoutdefault spacing="6" margin="11"/>
    109. <resources>
    110. <include location="thewge.qrc"/>
    111. </resources>
    112. <connections/>
    113. </ui>
    To copy to clipboard, switch view to plain text mode 



    and my generated header for the gui

    Qt Code:
    1. /********************************************************************************
    2. ** Form generated from reading UI file 'thewge.ui'
    3. **
    4. ** Created: Thu Jun 10 19:57:08 2010
    5. ** by: Qt User Interface Compiler version 4.6.2
    6. **
    7. ** WARNING! All changes made in this file will be lost when recompiling UI file!
    8. ********************************************************************************/
    9.  
    10. #ifndef UI_THEWGE_H
    11. #define UI_THEWGE_H
    12.  
    13. #include <QtCore/QVariant>
    14. #include <QtGui/QAction>
    15. #include <QtGui/QApplication>
    16. #include <QtGui/QButtonGroup>
    17. #include <QtGui/QHeaderView>
    18. #include <QtGui/QLineEdit>
    19. #include <QtGui/QMainWindow>
    20. #include <QtGui/QPushButton>
    21. #include <QtGui/QWidget>
    22.  
    23. QT_BEGIN_NAMESPACE
    24.  
    25. class Ui_TheWGEClass
    26. {
    27. public:
    28. QWidget *centralWidget;
    29. QLineEdit *usrLineEdit;
    30. QLineEdit *pwdLineEdit;
    31. QPushButton *LoginBtn;
    32.  
    33. void setupUi(QMainWindow *TheWGEClass)
    34. {
    35. if (TheWGEClass->objectName().isEmpty())
    36. TheWGEClass->setObjectName(QString::fromUtf8("TheWGEClass"));
    37. TheWGEClass->resize(649, 348);
    38. QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    39. sizePolicy.setHorizontalStretch(0);
    40. sizePolicy.setVerticalStretch(0);
    41. sizePolicy.setHeightForWidth(TheWGEClass->sizePolicy().hasHeightForWidth());
    42. TheWGEClass->setSizePolicy(sizePolicy);
    43. TheWGEClass->setMinimumSize(QSize(649, 348));
    44. TheWGEClass->setMaximumSize(QSize(649, 348));
    45. TheWGEClass->setStyleSheet(QString::fromUtf8("background-image: url(:/TheWGE/gamers.PNG)"));
    46. centralWidget = new QWidget(TheWGEClass);
    47. centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
    48. usrLineEdit = new QLineEdit(centralWidget);
    49. usrLineEdit->setObjectName(QString::fromUtf8("usrLineEdit"));
    50. usrLineEdit->setGeometry(QRect(270, 200, 170, 29));
    51. usrLineEdit->setMaximumSize(QSize(170, 29));
    52. usrLineEdit->setStyleSheet(QString::fromUtf8("background-image: url(:/TheWGE/textbox.PNG);\n"
    53. "color: rgb(255, 255, 255);"));
    54. usrLineEdit->setMaxLength(40);
    55. usrLineEdit->setFrame(false);
    56. pwdLineEdit = new QLineEdit(centralWidget);
    57. pwdLineEdit->setObjectName(QString::fromUtf8("pwdLineEdit"));
    58. pwdLineEdit->setGeometry(QRect(270, 230, 170, 29));
    59. pwdLineEdit->setMaximumSize(QSize(170, 29));
    60. pwdLineEdit->setStyleSheet(QString::fromUtf8("background-image: url(:/TheWGE/textbox.PNG);\n"
    61. "color: rgb(255, 255, 255);"));
    62. pwdLineEdit->setFrame(false);
    63. LoginBtn = new QPushButton(centralWidget);
    64. LoginBtn->setObjectName(QString::fromUtf8("LoginBtn"));
    65. LoginBtn->setGeometry(QRect(350, 270, 90, 31));
    66. LoginBtn->setStyleSheet(QString::fromUtf8("background-image: url(:/TheWGE/login.PNG)"));
    67. LoginBtn->setFlat(true);
    68. TheWGEClass->setCentralWidget(centralWidget);
    69.  
    70. retranslateUi(TheWGEClass);
    71. QObject::connect(LoginBtn, SIGNAL(clicked()), pwdLineEdit, SLOT(clear()));
    72.  
    73. QMetaObject::connectSlotsByName(TheWGEClass);
    74. } // setupUi
    75.  
    76. void retranslateUi(QMainWindow *TheWGEClass)
    77. {
    78. TheWGEClass->setWindowTitle(QApplication::translate("TheWGEClass", "TheWGE Anti-Cheat Client", 0, QApplication::UnicodeUTF8));
    79. LoginBtn->setText(QString());
    80. } // retranslateUi
    81.  
    82. };
    83.  
    84. namespace Ui {
    85. class TheWGEClass: public Ui_TheWGEClass {};
    86. } // namespace Ui
    87.  
    88. QT_END_NAMESPACE
    89.  
    90. #endif // UI_THEWGE_H
    To copy to clipboard, switch view to plain text mode 

    I thought by including the ui header and adding the slot would connect the 2 together. Its a new concept to me! if I am connecting controls or linking them but this is how I would think I would do that. The ui header is generated, so I could copy the code from there and paste it into a new file and add more info in there. I tried adding the connect using this from the UI header and it doesn't fire, like so.

    QObject::connect(LoginBtn, SIGNAL(clicked()), LoginBtn, SLOT(accept()));

    Thanks for your help!
    Last edited by wysota; 11th June 2010 at 21:34. Reason: changed [qtclass] to [code]

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT VS C++ 2005, QPushButton NOT FIRING!!!!!

    What I don't understand is that you have LoginBtn defined in both Ui_TheWGEClass and TheWGE. They are initialised by setupui() in Ui_TheWGEClass, but you are using the ones in TheWGE which seems puzzling. Why not just use the ones in Ui_TheWGEClass?

  5. The following user says thank you to squidge for this useful post:

    harleyskater (12th June 2010)

  6. #5
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT VS C++ 2005, QPushButton NOT FIRING!!!!!

    I am new to QT and after not getting my button to fire, I tried lots of things!

    where should I put this:

    QObject::connect(LoginBtn, SIGNAL(clicked()), LoginBtn, SLOT(accept()));

    and I doubt it should be button to button, but I am not sure how to point it to the class holding the function

  7. #6
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT VS C++ 2005, QPushButton NOT FIRING!!!!!

    Have you tried :
    Qt Code:
    1. QObject::connect(ui->LoginBtn, SIGNAL(clicked()), this, SLOT(accept()));
    To copy to clipboard, switch view to plain text mode 

  8. #7
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT VS C++ 2005, QPushButton NOT FIRING!!!!!

    yes I have tried that before, My attempt before was like this, I tried again and I got this set of errors. Though in my first attempt it was without the ui->LoginBtn, it was just LoginBtn

    1>Compiling...
    1>moc_thewge.cpp
    1>.\GeneratedFiles\ui_thewge.h(72) : error C2065: 'ui' : undeclared identifier
    1>.\GeneratedFiles\ui_thewge.h(72) : error C2227: left of '->LoginBtn' must point to class/struct/union/generic type
    1> type is ''unknown-type''


    Qt Code:
    1. /********************************************************************************
    2. ** Form generated from reading UI file 'thewge.ui'
    3. **
    4. ** Created: Fri Jun 11 13:01:58 2010
    5. ** by: Qt User Interface Compiler version 4.6.2
    6. **
    7. ** WARNING! All changes made in this file will be lost when recompiling UI file!
    8. ********************************************************************************/
    9.  
    10. #ifndef UI_THEWGE_H
    11. #define UI_THEWGE_H
    12.  
    13. #include <QtCore/QVariant>
    14. #include <QtGui/QAction>
    15. #include <QtGui/QApplication>
    16. #include <QtGui/QButtonGroup>
    17. #include <QtGui/QHeaderView>
    18. #include <QtGui/QLineEdit>
    19. #include <QtGui/QMainWindow>
    20. #include <QtGui/QPushButton>
    21. #include <QtGui/QWidget>
    22.  
    23. QT_BEGIN_NAMESPACE
    24.  
    25. class Ui_TheWGEClass
    26. {
    27. public:
    28. QWidget *centralWidget;
    29. QLineEdit *usrLineEdit;
    30. QLineEdit *pwdLineEdit;
    31. QPushButton *LoginBtn;
    32.  
    33. void setupUi(QMainWindow *TheWGEClass)
    34. {
    35. if (TheWGEClass->objectName().isEmpty())
    36. TheWGEClass->setObjectName(QString::fromUtf8("TheWGEClass"));
    37. TheWGEClass->resize(649, 348);
    38. QSizePolicy sizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    39. sizePolicy.setHorizontalStretch(0);
    40. sizePolicy.setVerticalStretch(0);
    41. sizePolicy.setHeightForWidth(TheWGEClass->sizePolicy().hasHeightForWidth());
    42. TheWGEClass->setSizePolicy(sizePolicy);
    43. TheWGEClass->setMinimumSize(QSize(649, 348));
    44. TheWGEClass->setMaximumSize(QSize(649, 348));
    45. TheWGEClass->setStyleSheet(QString::fromUtf8("background-image: url(:/TheWGE/gamers.PNG)"));
    46. centralWidget = new QWidget(TheWGEClass);
    47. centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
    48. usrLineEdit = new QLineEdit(centralWidget);
    49. usrLineEdit->setObjectName(QString::fromUtf8("usrLineEdit"));
    50. usrLineEdit->setGeometry(QRect(270, 200, 170, 29));
    51. usrLineEdit->setMaximumSize(QSize(170, 29));
    52. usrLineEdit->setStyleSheet(QString::fromUtf8("background-image: url(:/TheWGE/textbox.PNG);\n"
    53. "color: rgb(255, 255, 255);"));
    54. usrLineEdit->setMaxLength(40);
    55. usrLineEdit->setFrame(false);
    56. pwdLineEdit = new QLineEdit(centralWidget);
    57. pwdLineEdit->setObjectName(QString::fromUtf8("pwdLineEdit"));
    58. pwdLineEdit->setGeometry(QRect(270, 230, 170, 29));
    59. pwdLineEdit->setMaximumSize(QSize(170, 29));
    60. pwdLineEdit->setStyleSheet(QString::fromUtf8("background-image: url(:/TheWGE/textbox.PNG);\n"
    61. "color: rgb(255, 255, 255);"));
    62. pwdLineEdit->setFrame(false);
    63. LoginBtn = new QPushButton(centralWidget);
    64. LoginBtn->setObjectName(QString::fromUtf8("LoginBtn"));
    65. LoginBtn->setGeometry(QRect(350, 270, 90, 31));
    66. LoginBtn->setStyleSheet(QString::fromUtf8("background-image: url(:/TheWGE/login.PNG)"));
    67. LoginBtn->setFlat(true);
    68. TheWGEClass->setCentralWidget(centralWidget);
    69.  
    70. retranslateUi(TheWGEClass);
    71.  
    72. QObject::connect(ui->LoginBtn, SIGNAL(clicked()), this, SLOT(accept()));
    73.  
    74. QMetaObject::connectSlotsByName(TheWGEClass);
    75. } // setupUi
    76.  
    77. void retranslateUi(QMainWindow *TheWGEClass)
    78. {
    79. TheWGEClass->setWindowTitle(QApplication::translate("TheWGEClass", "TheWGE Anti-Cheat Client", 0, QApplication::UnicodeUTF8));
    80. LoginBtn->setText(QString());
    81. } // retranslateUi
    82.  
    83. };
    84.  
    85. namespace Ui {
    86. class TheWGEClass: public Ui_TheWGEClass {};
    87. } // namespace Ui
    88.  
    89. QT_END_NAMESPACE
    90.  
    91. #endif // UI_THEWGE_H
    To copy to clipboard, switch view to plain text mode 

  9. #8
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT VS C++ 2005, QPushButton NOT FIRING!!!!!

    Why are you modifying ui_thewge.h? That file is automatically generated so you will loose your changes! Do not edit that file!

  10. #9
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT VS C++ 2005, QPushButton NOT FIRING!!!!!

    LOL, all of my posts on this thread have said that I don't know where to put the connect statement, it would be much easier if you just told me where it belongs

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QT VS C++ 2005, QPushButton NOT FIRING!!!!!

    Your problem has nothing to do with Qt, you know. It's pure lack of C++ skills. Sorry for being blunt but then you didn't have to SHOUT(!) in the first place and you could have used proper tags in your posts
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #11
    Join Date
    Jun 2010
    Posts
    41
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT VS C++ 2005, QPushButton NOT FIRING!!!!!

    i've already built this, in managed code with .net forms in C++, but I want to get away from that with QT so my program will be more secure. I've only been programming C++ for a year, im no pro but Its not that I don't know C++. why can I put 6 posts in 1 thread with all my code asking why a button isn't firing and still have not gotten any real advice?
    Last edited by harleyskater; 11th June 2010 at 21:51.

Similar Threads

  1. Replies: 0
    Last Post: 22nd February 2010, 09:30
  2. QSocketNotifier activated() not firing
    By jflatt in forum Qt Programming
    Replies: 1
    Last Post: 10th July 2009, 20:10
  3. Qt 4.3.2 with VS 2005 SP1
    By Shawn in forum Installation and Deployment
    Replies: 1
    Last Post: 12th October 2007, 07:04
  4. QT with visual c++ 2005
    By v3n0w in forum Installation and Deployment
    Replies: 5
    Last Post: 20th May 2007, 12:37
  5. Replies: 3
    Last Post: 26th September 2006, 12:16

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.