sd.CSharpProgrammer
پنج شنبه 03 آذر 1390, 14:15 عصر
سلام دوستان
من این برنامه رو تو کیوت نوشتم. برنامه خطای نحوی نداره و بدون مشکل کامپایل میشه ولی وقتی میخوام اجراش کنم بجای اینکه پنجره برنامه بیاد، یه پیغام خطا از طرف ویندوز میاد.
دوستان هر چی این کد رو میبینم مشکل خاصی توش پیدا نمیکنم، اگر جایی سوتی دادم بگید :لبخند:
HelloWorld.pro
SOURCES += \ main.cpp \ qhelloworldwidget.cpp HEADERS += \ qhelloworldwidget.h
qhelloworldwidget.h
#ifndef QHELLOWORLDWIDGET_H #define QHELLOWORLDWIDGET_H #include <QLabel> #include <QLineEdit> #include <QPushButton> #include <QHBoxLayout> #include <QVBoxLayout> #include <QMessageBox> class QHelloWorldWidget : public QWidget { Q_OBJECT public: QHelloWorldWidget(); private: QLabel *label; QLineEdit *lineEdit; QPushButton *ok; QPushButton *cancel; QHBoxLayout *hLay; QVBoxLayout *vLay1; QVBoxLayout *vLay2; private slots: void showMessage(); }; #endif // QHELLOWORLDWIDGET_H
qhelloworldwidget.cpp
#include "qhelloworldwidget.h" QHelloWorldWidget::QHelloWorldWidget() { label = new QLabel("Enter Text :"); lineEdit = new QLineEdit(); ok = new QPushButton("OK"); cancel = new QPushButton("Cancel"); connect(ok, SIGNAL(clicked()), this, SLOT(showMessage())); connect(cancel, SIGNAL(clicked()), this, SLOT(close())); vLay1 = new QVBoxLayout; vLay1->addWidget(label); vLay1->addWidget(lineEdit); hLay = new QHBoxLayout; hLay->addSpacing(75); hLay->addWidget(ok); hLay->addWidget(cancel); vLay2->addLayout(vLay1); vLay2->addLayout(hLay); setLayout(vLay2); } void QHelloWorldWidget::showMessage() { QMessageBox::information(this, "HelloWorldWidget Sample", lineEdit->text(), QMessageBox::Ok); }
main.cpp
#include <QApplication> #include "qhelloworldwidget.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); QHelloWorldWidget *widget = new QHelloWorldWidget; widget->show(); return a.exec(); }
من این برنامه رو تو کیوت نوشتم. برنامه خطای نحوی نداره و بدون مشکل کامپایل میشه ولی وقتی میخوام اجراش کنم بجای اینکه پنجره برنامه بیاد، یه پیغام خطا از طرف ویندوز میاد.
دوستان هر چی این کد رو میبینم مشکل خاصی توش پیدا نمیکنم، اگر جایی سوتی دادم بگید :لبخند:
HelloWorld.pro
SOURCES += \ main.cpp \ qhelloworldwidget.cpp HEADERS += \ qhelloworldwidget.h
qhelloworldwidget.h
#ifndef QHELLOWORLDWIDGET_H #define QHELLOWORLDWIDGET_H #include <QLabel> #include <QLineEdit> #include <QPushButton> #include <QHBoxLayout> #include <QVBoxLayout> #include <QMessageBox> class QHelloWorldWidget : public QWidget { Q_OBJECT public: QHelloWorldWidget(); private: QLabel *label; QLineEdit *lineEdit; QPushButton *ok; QPushButton *cancel; QHBoxLayout *hLay; QVBoxLayout *vLay1; QVBoxLayout *vLay2; private slots: void showMessage(); }; #endif // QHELLOWORLDWIDGET_H
qhelloworldwidget.cpp
#include "qhelloworldwidget.h" QHelloWorldWidget::QHelloWorldWidget() { label = new QLabel("Enter Text :"); lineEdit = new QLineEdit(); ok = new QPushButton("OK"); cancel = new QPushButton("Cancel"); connect(ok, SIGNAL(clicked()), this, SLOT(showMessage())); connect(cancel, SIGNAL(clicked()), this, SLOT(close())); vLay1 = new QVBoxLayout; vLay1->addWidget(label); vLay1->addWidget(lineEdit); hLay = new QHBoxLayout; hLay->addSpacing(75); hLay->addWidget(ok); hLay->addWidget(cancel); vLay2->addLayout(vLay1); vLay2->addLayout(hLay); setLayout(vLay2); } void QHelloWorldWidget::showMessage() { QMessageBox::information(this, "HelloWorldWidget Sample", lineEdit->text(), QMessageBox::Ok); }
main.cpp
#include <QApplication> #include "qhelloworldwidget.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); QHelloWorldWidget *widget = new QHelloWorldWidget; widget->show(); return a.exec(); }