Mi a hiba? (c++, Qt) (Dialógus ablak Emil, név bekérése)
//main.cpp
#include "contactdialog.h"
#include <QApplication>
#include<QtGui>
#include<QString>
#include<QGroupBox>
#include<QLabel>
#include<QLineEdit>
#include <QPushButton>
#include<QGridLayout>
#include<QVBoxLayout>
#include<QHBoxLayout>
#include<QMessageBox>
#include<QStringBuilder>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
ContactDialog *dlg = new ContactDialog();
dlg->exec();
QMessageBox msg;
msg.setWindowTitle("Eredmény:");
QString message =
"Név: " % dlg->getName() %
", email: " % dlg->getEmail() %
(dlg->result()==QDialog::Accepted
?"(jóváhagva)"
:"(nincs jóváhagyva)");
msg.setText(message);
msg.show();
return app.exec();
}
//contactdialog.cpp
#include "contactdialog.h"
#include<QtGui>
#include<QString>
#include<QGroupBox>
#include<QLabel>
#include<QLineEdit>
#include <QPushButton>
#include<QGridLayout>
#include<QVBoxLayout>
#include<QHBoxLayout>
ContactDialog::ContactDialog(QWidget *parent)
: QDialog(parent)
{
this->setWindowTitle("Új bejegyzés");
group =new QGroupBox;
lblName = new QLabel("NÉV:");
lblEmail =new QLabel("Emil:");
txtName = new QLineEdit();
txtEmail = new QLineEdit();
grid = new QGroupBox("Adatok:");
grid->addWidget(lblName, 0,0);
grid->addWidget(txtName, 0,1);
grid->addWidget(lblEmail,1,0);
grid->addWidget(txtEmail, 1,1);
gruop->setLayout(grid);
btnOk= new QPushButton("Rendben:");
btnCancel = new QPushButton("Mégsem");
buttonLayout = new QHBoxLayout;
buttonLayout-> addStretch();
buttonLayout->addWidget(btnOk);
buttonLayout->addWidget(btnCancel);
mainLayout = new QVBoxLayout;
this->setLayout(mainLayout);
mainLayout->addWidget(group);
mainLayout->addStretch();
mainLayout->addLayout(buttonLayout);
connect(btnOk, SIGNAL(clicked()),this, SLOT(accept()));
connect(btnCancel, SIGNAL(clicked()),this, SLOT(reject()));
}
QString ContactDialog::getName()
{return txtName->text();}
QString ContactDialog::getEmail()
{return txtEmail->text();}
//contactdialog.h
#ifndef CONTACTDIALOG_H
#define CONTACTDIALOG_H
#include<QtGui>
#include<QString>
#include<QGroupBox>
#include<QLabel>
#include<QLineEdit>
#include <QPushButton>
#include<QGridLayout>
#include<QVBoxLayout>
#include<QHBoxLayout>
class ContactDialog : public QDialog
{
Q_OBJECT
public:
ContactDialog(QWidget *parent = 0);
QString getName();
QString getEmail();
private:
QGroupBox *group;
QLabel *lblName;
QLabel *lblEmail;
QLineEdit *txtName;
QLineEdit *txtEmail;
QPushButton *btnOk;
QPushButton *btnCancel;
QGridLayout *grid;
QVBoxLayout *mainLayout;
QHBoxLayout *buttonLayout;
};
#endif // CONTACTDIALOG_H
Kapcsolódó kérdések:
Minden jog fenntartva © 2024, www.gyakorikerdesek.hu
GYIK | Szabályzat | Jogi nyilatkozat | Adatvédelem | Cookie beállítások | WebMinute Kft. | Facebook | Kapcsolat: info(kukac)gyakorikerdesek.hu
Ha kifogással szeretne élni valamely tartalommal kapcsolatban, kérjük jelezze e-mailes elérhetőségünkön!