Page 1 of 2 12 LastLast
Results 1 to 20 of 21

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

  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 22: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 22:51.

  13. #12
    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!!!!!

    Quote Originally Posted by harleyskater View Post
    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?
    That's very simple to answer - because you didn't provide proper information in your first post. Each reply to each of your posts in this thread provides a proper answer to the problem stated in the previous post. First you asked why the application crashes and you were given the answer that it is because you had been using an uninitialized variable which was the proper answer to your question as your variables were obviously uninitialized. Of course after a year of C++ programming you should have noticed that yourself but ok... Then you stated you thought you had them initialized and posted a ui file (which you should have attached to your post instead of posting it inline with wrong bbcode, by the way) which was not that much relevant as the unitialized variable was the one in your widget class and not in the form. Fatjuicymole pointed out you had two sets of variables with the same names which again was the proper answer to your statement. Then you asked where you should put the connect statement connecting your uninitialized variable to something else. You were then given a good advice to use the variable from your ui class instead of the uninitialized variable. Then you said you had tried that before and it gave you some errors that you posted. The answer (again the right one) was that you placed it in a wrong place. Of course after programming in C++ for a year you should have noticed you didn't have a "ui" variable in this scope or you should have understood the clear message from the compiler you had been using for a year, but who am I to judge...

    So to summarize, you had the following problem history:
    1. you used an unexisting "ui" variable in a connect statement which gave you errors you didn't understand
    2. you removed the offending line and instead made another mistake of declaring a variable of the same name in your widget class, forgetting to initialize it and using it in a connect statement
    3. you were told you should have used the variable from the ui file which led you back to your original problem (or rather misled you as you just needed to add "ui->" to your statement and you simply misinterpreted it)
    4. you told me you have little experience with C++ because you have been using it for only a year but you are used to .Net (meaning probably C#, which is also object oriented so you should have spotted both your problems as in C# they would be exactly the same) causing another headache and wondering why majority of problems on this forum recently is related to C++ and not Qt and thinking whether we should introduce some kind of "basic C++ knowledge" certification process for people registering on this forum.

    I hope I clarified the situation. If not, let me know what is still unclear and we'll try to provide a better explanation.
    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.


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

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

    i've never worked with C# before, just managed C++ Form applications. I am working away from that because a recent program of mine was decompiled. I could use a fuscator but I read all these things about QT and crossplatforms the programs I am building will soon be needed for mac. It didn't take me any time to program this, but its taken me 3 days to program out this with QT and really my main problem is understanding how to access the UI. I read what you said and I still don't understand where my connect should go, I am guessing my thewge.h. I don't understand what you mean by needing the "ui->". I am just trying to take this project that I have already done, and make it into a project that uses QT.

    Qt Code:
    1. #pragma once
    2.  
    3. #include <mysql++.h>
    4. #include <windows.h>
    5. #include <iostream>
    6. #include "md5.h"
    7.  
    8. namespace wforms {
    9.  
    10. using namespace System;
    11. using namespace System::ComponentModel;
    12. using namespace System::Collections;
    13. using namespace System::Windows::Forms;
    14. using namespace System::Data;
    15. using namespace System::Drawing;
    16.  
    17. /// <summary>
    18. /// Summary for LoginForm
    19. /// </summary>
    20. public ref class LoginForm : public System::Windows::Forms::Form
    21. {
    22. public:
    23. LoginForm(void)
    24. {
    25. InitializeComponent();
    26. //
    27. //TODO: Add the constructor code here
    28. //
    29. }
    30.  
    31. protected:
    32. /// <summary>
    33. /// Clean up any resources being used.
    34. /// </summary>
    35. ~LoginForm()
    36. {
    37. if (components)
    38. {
    39. delete components;
    40. }
    41. }
    42. internal: System::Windows::Forms::Button^ Cancel;
    43. protected:
    44. internal: System::Windows::Forms::Button^ OK;
    45. internal: System::Windows::Forms::TextBox^ PasswordTextBox;
    46. internal: System::Windows::Forms::TextBox^ UsernameTextBox;
    47. internal: System::Windows::Forms::Label^ PasswordLabel;
    48. internal: System::Windows::Forms::Label^ UsernameLabel;
    49. internal: System::Windows::Forms::PictureBox^ LogoPictureBox;
    50.  
    51. private:
    52. /// <summary>
    53. /// Required designer variable.
    54. /// </summary>
    55. System::ComponentModel::Container ^components;
    56.  
    57. #pragma region Windows Form Designer generated code
    58. /// <summary>
    59. /// Required method for Designer support - do not modify
    60. /// the contents of this method with the code editor.
    61. /// </summary>
    62. void InitializeComponent(void)
    63. {
    64. System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(LoginForm::typeid));
    65. this->Cancel = (gcnew System::Windows::Forms::Button());
    66. this->OK = (gcnew System::Windows::Forms::Button());
    67. this->PasswordTextBox = (gcnew System::Windows::Forms::TextBox());
    68. this->UsernameTextBox = (gcnew System::Windows::Forms::TextBox());
    69. this->PasswordLabel = (gcnew System::Windows::Forms::Label());
    70. this->UsernameLabel = (gcnew System::Windows::Forms::Label());
    71. this->LogoPictureBox = (gcnew System::Windows::Forms::PictureBox());
    72. (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->LogoPictureBox))->BeginInit();
    73. this->SuspendLayout();
    74. //
    75. // Cancel
    76. //
    77. this->Cancel->DialogResult = System::Windows::Forms::DialogResult::Cancel;
    78. this->Cancel->Location = System::Drawing::Point(313, 190);
    79. this->Cancel->Name = L"Cancel";
    80. this->Cancel->Size = System::Drawing::Size(94, 23);
    81. this->Cancel->TabIndex = 12;
    82. this->Cancel->Text = L"&Cancel";
    83. this->Cancel->Click += gcnew System::EventHandler(this, &LoginForm::Cancel_Click);
    84. //
    85. // OK
    86. //
    87. this->OK->Location = System::Drawing::Point(210, 190);
    88. this->OK->Name = L"OK";
    89. this->OK->Size = System::Drawing::Size(94, 23);
    90. this->OK->TabIndex = 11;
    91. this->OK->Text = L"&OK";
    92. this->OK->Click += gcnew System::EventHandler(this, &LoginForm::OK_Click);
    93. //
    94. // PasswordTextBox
    95. //
    96. this->PasswordTextBox->Location = System::Drawing::Point(187, 130);
    97. this->PasswordTextBox->Name = L"PasswordTextBox";
    98. this->PasswordTextBox->PasswordChar = '*';
    99. this->PasswordTextBox->Size = System::Drawing::Size(220, 20);
    100. this->PasswordTextBox->TabIndex = 10;
    101. //
    102. // UsernameTextBox
    103. //
    104. this->UsernameTextBox->Location = System::Drawing::Point(187, 73);
    105. this->UsernameTextBox->Name = L"UsernameTextBox";
    106. this->UsernameTextBox->Size = System::Drawing::Size(220, 20);
    107. this->UsernameTextBox->TabIndex = 8;
    108. //
    109. // PasswordLabel
    110. //
    111. this->PasswordLabel->Location = System::Drawing::Point(185, 110);
    112. this->PasswordLabel->Name = L"PasswordLabel";
    113. this->PasswordLabel->Size = System::Drawing::Size(220, 23);
    114. this->PasswordLabel->TabIndex = 9;
    115. this->PasswordLabel->Text = L"&Password";
    116. this->PasswordLabel->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
    117. //
    118. // UsernameLabel
    119. //
    120. this->UsernameLabel->Location = System::Drawing::Point(185, 53);
    121. this->UsernameLabel->Name = L"UsernameLabel";
    122. this->UsernameLabel->Size = System::Drawing::Size(220, 23);
    123. this->UsernameLabel->TabIndex = 6;
    124. this->UsernameLabel->Text = L"&User name";
    125. this->UsernameLabel->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
    126. //
    127. // LogoPictureBox
    128. //
    129. this->LogoPictureBox->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"LogoPictureBox.Image")));
    130. this->LogoPictureBox->Location = System::Drawing::Point(13, 69);
    131. this->LogoPictureBox->Name = L"LogoPictureBox";
    132. this->LogoPictureBox->Size = System::Drawing::Size(168, 81);
    133. this->LogoPictureBox->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
    134. this->LogoPictureBox->TabIndex = 7;
    135. this->LogoPictureBox->TabStop = false;
    136. //
    137. // LoginForm
    138. //
    139. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    140. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    141. this->ClientSize = System::Drawing::Size(421, 266);
    142. this->Controls->Add(this->Cancel);
    143. this->Controls->Add(this->OK);
    144. this->Controls->Add(this->PasswordTextBox);
    145. this->Controls->Add(this->UsernameTextBox);
    146. this->Controls->Add(this->PasswordLabel);
    147. this->Controls->Add(this->UsernameLabel);
    148. this->Controls->Add(this->LogoPictureBox);
    149. this->Name = L"LoginForm";
    150. this->Text = L"LoginForm";
    151. (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->LogoPictureBox))->EndInit();
    152. this->ResumeLayout(false);
    153. this->PerformLayout();
    154.  
    155. }
    156. #pragma endregion
    157.  
    158. // Takes a string in the .NET platform's native Unicode format and
    159. // copies it to the given C string buffer in UTF-8 encoding.
    160. Void ToUTF8(char* pcOut, int nOutLen, String^ sIn)
    161. {
    162. array<Byte>^ bytes = System::Text::Encoding::UTF8->GetBytes(sIn);
    163. nOutLen = Math::Min(nOutLen - 1, bytes->Length);
    164. System::Runtime::InteropServices::Marshal::Copy(bytes, 0,
    165. IntPtr(pcOut), nOutLen);
    166. pcOut[nOutLen] = '\0';
    167. }
    168.  
    169.  
    170. private: System::Void OK_Click(System::Object^ sender, System::EventArgs^ e)
    171. {
    172.  
    173.  
    174. mysqlpp::Connection con(false);
    175.  
    176. if (!con.connect("db", "server", "thewge", "password"))
    177. {
    178. Application::Exit();
    179. }
    180.  
    181. // Retrieve a subset of the sample stock table set up by resetdb
    182. mysqlpp::Query query = con.query();
    183. //query << "SELECT username, password FROM wge_db_user WHERE username = 'da*beast'";
    184.  
    185. const int kInputBufSize = 100;
    186. char acsUserName[kInputBufSize];
    187. char acsPassword[kInputBufSize];
    188.  
    189. ToUTF8(acsUserName, kInputBufSize, UsernameTextBox->Text);
    190. ToUTF8(acsPassword, kInputBufSize, PasswordTextBox->Text);
    191.  
    192. //md5(acsPassword);
    193.  
    194. query << "SELECT username, password FROM wge_db_user WHERE username = '" << acsUserName << "' and password = '" << md5(acsPassword) << "'";
    195.  
    196. mysqlpp::StoreQueryResult res = query.store();
    197. mysqlpp::Row row;
    198.  
    199.  
    200. if (res.num_rows() > 0)
    201. {
    202. //goodlogin - show new form and hide this form
    203. }
    204. else
    205. {
    206. //badlogin
    207. }
    208.  
    209. mysqlpp::Connection::thread_end();
    210.  
    211.  
    212. return;
    213.  
    214.  
    215. }
    216. private: System::Void Cancel_Click(System::Object^ sender, System::EventArgs^ e)
    217. {
    218. Application::Exit();
    219. }
    220. };
    221.  
    222. }
    To copy to clipboard, switch view to plain text mode 




    the things are throwing me off is the generated file and talking and connecting from other forms to the QT GUI


    where should my connect code go, what should it look like and what is the steps needed to get it connected to a function.


    I just came here for help, I thought this would be a simple question and answer because its just a button click event..............

  15. #14
    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!!!!!

    Quote Originally Posted by harleyskater View Post
    i've never worked with C# before, just managed C++ Form applications.
    Whatever - still object oriented.

    I am working away from that because a recent program of mine was decompiled.
    Every C++ application can be decompiled and disassembled.
    I read what you said and I still don't understand where my connect should go,
    It should be in the constructor of your widget class.

    I don't understand what you mean by needing the "ui->"
    You are familiar with the "->" operator in C++, right?



    the things are throwing me off is the generated file and talking and connecting from other forms to the QT GUI
    So don't generate any files, write everything manually. Nobody forces you to use ui files.

    I just came here for help, I thought this would be a simple question and answer because its just a button click event..............
    But your problem has really nothing to do with any buttons. It's a simple C++ issue of accessing an uninitialized (in one case) or non-existing (in the other case) variable.
    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.


  16. #15
    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!!!!!

    You had it in the right place the first time. No one told you to move that statement to another file, which is why when I told you the correct way to use the connect method it didn't work for you. I was (and still am) puzzled why you changed the file, and then when I say you got the wrong file you start complaining that no one is giving you real advice.

    Sheesh. It's a wonder anyone helps you.

  17. #16
    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!!!!!

    Just to correct what I said earlier - I just noticed "ui" was not a pointer in your code (I'm answering too many threads at the same time :P) so it should be "ui." and not "ui->". The rest still stands.
    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.


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

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

    juicy, I just realized why this was giving me so many problems, it was actually firing, but my breaks in my code were not stopping the debug : / I am guessing there something between QT and MSVC that isn't great for debugging. thxfor your help

  19. #18
    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!!!!!

    Yep, blame Qt, that's really an easy way to improve your self esteem...
    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.


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

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

    http://www.wysota.eu.org/wwwidgets/

    my web design skills were better than that in 5th grade. you get on forums and pick on people learning to program? im 16 years old. sorry i haven't been programming 30 years. go back to ugly town... ugly

  21. #20
    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!!!!!

    Quote Originally Posted by harleyskater View Post
    http://www.wysota.eu.org/wwwidgets/
    my web design skills were better than that in 5th grade.
    That's fine, that site is not about designing webpages but about programming widgets. If you want, we can compare our skills in that domain. I'm a lousy web designer, that's true.

    I just don't like when people are looking for excuses to their actions not ending up as they wanted by pushing the blame on something (or someone) else. That's nothing personal, really. I think it just looks (and works) better if you say "I did something wrong" and somebody else says "No, it's not your fault, it's just X isn't good in Y. It was a good try". On the other hand if you say "I'm so great, it's just the tools I use suck" an answer to that is simple - use different tools. It's not a problem when someone makes a mistake. It becomes a problem when he is not able to admit he made it.
    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.


Similar Threads

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