I've been trying to find a solution to this on my own this past week, but have been confounded every step of the way.

I am using MSVS.NET(2003) and QT 3.2.1 Non-Commercial.

I coded a simple dialog which accepts a QStringList as an argument in the constructor, and this list is displayed in a QComboBox (which is a private attribute of the class). I wish to use an instance of QPushButton to pass the value of the selected variable to another class using emit. However, after the slot method which deals with this processing is called when the push button recieves a clicked() signal, I cannot access the QComboBox and thus obtain its current value using the methods.

airportselectdialog.h
Qt Code:
  1. #ifndef AIRPORTSELECTDIALOG_H
  2. #define AIRPORTSELECTDIALOG_H
  3.  
  4. #include <qdialog.h>
  5.  
  6. using std::string;
  7.  
  8. class QComboBox;
  9. class Airport;
  10. class QLabel;
  11.  
  12. class AirportSelectDialog : public QDialog
  13. {
  14. Q_OBJECT
  15. public:
  16. AirportSelectDialog(const QStringList airportList, QWidget *parent = 0, const char *name = 0);
  17.  
  18. signals:
  19. void QSetAirport(const QString &str);
  20.  
  21. private slots:
  22. void selectClicked();
  23.  
  24. private:
  25. QLabel* label;
  26. QComboBox *airportBox;
  27. QPushButton *selectButton;
  28. };
  29.  
  30. #endif
To copy to clipboard, switch view to plain text mode 

airportselectdialog.cpp - (comments added as means of conveying my problem)
Qt Code:
  1. #include <qcombobox.h>
  2. #include <qpushbutton.h>
  3. #include <qlabel.h>
  4. #include <qlayout.h>
  5.  
  6. #include "airportselectdialog.h"
  7.  
  8. AirportSelectDialog::AirportSelectDialog(const QStringList airportList, QWidget *parent, const char *name)
  9. : QDialog(parent, name)
  10. {
  11. setCaption(tr("Select Airport"));
  12.  
  13. label = new QLabel(tr("Your Airport:"), this);
  14.  
  15. QComboBox *airportBox = new QComboBox(this);
  16. airportBox->insertStringList(airportList);
  17. label->setBuddy(airportBox);
  18.  
  19. QPushButton *selectButton = new QPushButton(tr("Select"),this);
  20. selectButton->setDefault(true);
  21. selectButton->setEnabled(true);
  22. connect(selectButton, SIGNAL(clicked()),
  23. this, SLOT(selectClicked()));
  24.  
  25. QHBoxLayout *leftLayout = new QHBoxLayout;
  26. leftLayout->addWidget(label);
  27. leftLayout->addWidget(airportBox);
  28.  
  29. QHBoxLayout *rightLayout = new QHBoxLayout;
  30. rightLayout->addWidget(selectButton);
  31.  
  32. QHBoxLayout *mainLayout = new QHBoxLayout(this);
  33. mainLayout->setMargin(11);
  34. mainLayout->setSpacing(6);
  35. mainLayout->addLayout(leftLayout);
  36. mainLayout->addLayout(rightLayout);
  37. }
  38.  
  39. void AirportSelectDialog::selectClicked()
  40. {
  41. QString text = airportBox->currentText(); // This does not work!
  42. /* I have also tried accessing selectButton from here, to no avail! */
  43.  
  44.  
  45. /* Unhandled exception at 0x004014fa in Airport Booking System.exe: 0xC0000005: Access violation reading location 0xbaadf00d */
  46.  
  47. emit QSetAirport(text); // here signal will be caught by slot in seperate class
  48. close();
  49. }
To copy to clipboard, switch view to plain text mode 

There are no errors/warnings during compilation, and the dialog is created as a popup window which will close once item selected from QComboBox.