Skip to content

Instantly share code, notes, and snippets.

@aagontuk
Created April 6, 2016 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aagontuk/a694ea716221818a28c5d1b8d546e0f9 to your computer and use it in GitHub Desktop.
Save aagontuk/a694ea716221818a28c5d1b8d546e0f9 to your computer and use it in GitHub Desktop.
Crashed QT Application
#include "ByteConverterDialog.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
#include <QLineEdit>
#include <QIntValidator>
#include <QRegExpValidator>
ByteConverterDialog::ByteConverterDialog(){
QVBoxLayout *mainLayout = new QVBoxLayout;
QHBoxLayout *buttonLayout = new QHBoxLayout;
QGridLayout *editLayout = new QGridLayout;
mainLayout->addLayout(editLayout);
mainLayout->addStretch();
mainLayout->addLayout(buttonLayout);
QLabel *decLabel = new QLabel(tr("Decimal"));
QLabel *hexLabel = new QLabel(tr("Hexadecimal"));
QLabel *binLabel = new QLabel(tr("Binary"));
editLayout->addWidget(decLabel, 0, 0);
editLayout->addWidget(decEdit, 0, 1);
editLayout->addWidget(hexLabel, 1, 0);
editLayout->addWidget(hexEdit, 1, 1);
editLayout->addWidget(binLabel, 2, 0);
editLayout->addWidget(binEdit, 2, 1);
QPushButton *quitButton = new QPushButton;
quitButton->setDefault(true);
buttonLayout->addStretch();
buttonLayout->addWidget(quitButton);
QIntValidator *decValidator = new QIntValidator(0, 255, decEdit);
decEdit->setValidator(decValidator);
QRegExpValidator *hexValidator = new QRegExpValidator(QRegExp("[0-9A-Fa-f]{1,2}"), hexEdit);
hexEdit->setValidator(hexValidator);
QRegExpValidator *binValidator = new QRegExpValidator(QRegExp("[0-1]{1,8}"), binEdit);
binEdit->setValidator(binValidator);
setWindowTitle(tr("Byte Converter Dialog"));
}
#ifndef BYTE_CONVERTER_DIALOG_H
#define BYTE_CONVERTER_DIALOG_H
#include <QDialog>
class QLineEdit;
class ByteConverterDialog: public QDialog{
Q_OBJECT
public:
ByteConverterDialog();
private:
QLineEdit *decEdit;
QLineEdit *hexEdit;
QLineEdit *binEdit;
};
#endif
######################################################################
# Automatically generated by qmake (3.0) Thu Apr 7 00:21:42 2016
######################################################################
QT += core gui widgets
TEMPLATE = app
TARGET = hello
INCLUDEPATH += .
# Input
HEADERS += ByteConverterDialog.h
SOURCES += ByteConverterDialog.cpp main.cpp
#include <QApplication>
#include "ByteConverterDialog.h"
int main(int argc, char *argv[]){
QApplication app(argc, argv);
ByteConverterDialog bc;
bc.setAttribute(Qt::WA_QuitOnClose);
bc.show();
return app.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment