#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
#include <Qt\QApplication.h>
#include "ByteConverterDialog.h"
int main(int argc, char *argv[])
{
ByteConverterDialog bc;
bc.setAttribute(Qt::WA_QuitOnClose);
bc.show();
return a.exec();
};
#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
#include <Qt\QApplication.h>
#include "ByteConverterDialog.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
ByteConverterDialog bc;
bc.setAttribute(Qt::WA_QuitOnClose);
bc.show();
return a.exec();
};
To copy to clipboard, switch view to plain text mode
#include "ByteConverterDialog.h"
#include <QtGui/QLabel.h>
#include <QtGui/QLineEdit.h>
#include <QtGui/QPushButton.h>
#include <QtGui/QVBoxLayout.h>
#include <QtGui/QHBoxLayout.h>
#include <QtGui/QGridLayout.h>
#include <QtGui/QIntValidator>
ByteConverterDialog::ByteConverterDialog()
{
mainLayout->addLayout(editLayout);
mainLayout->addStretch();
mainLayout->addLayout(buttonLayout);
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);
buttonLayout->addStretch();
buttonLayout->addWidget(exitButton);
exitButton->setDefault(true);
decEdit->setValidator(decValidator);
hexEdit->setValidator(hexValidator);
binEdit->setValidator(binValidator);
setWindowTitle(tr("Byte Converter"));
QObject::connect(exitButton,
SIGNAL(clicked
()),
this,
SLOT(accept
()));
QObject::connect(decEdit,
SIGNAL(textChanged
(const QString
&)),
this,
SLOT(decChanged
(const QString
&)));
QObject::connect(hexEdit,
SIGNAL(textChanged
(const QString
&)),
this,
SLOT(hexChanged
(const QString
&)));
QObject::connect(binEdit,
SIGNAL(textChanged
(const QString
&)),
this,
SLOT(binChanged
(const QString
&)));
}
void ByteConverterDialog::decChanged(const QString& newValue)
{
bool ok;
int num=newValue.toInt(&ok);
if(ok)
{
hexEdit
->setText
(QString::number(num,
16));
binEdit
->setText
(QString::number(num,
2));
}
else
{
hexEdit->setText("");
binEdit->setText("");
}
}
void ByteConverterDialog::hexChanged(const QString& newValue)
{
bool ok;
int num=newValue.toInt(&ok,16);
if(ok)
{
decEdit
->setText
(QString::number(num
));
binEdit
->setText
(QString::number(num,
2));
}
else
{
decEdit->setText("");
binEdit->setText("");
}
}
void ByteConverterDialog::binChanged(const QString& newValue)
{
bool ok;
int num=newValue.toInt(&ok,2);
if(ok)
{
decEdit
->setText
(QString::number(num
));
hexEdit
->setText
(QString::number(num,
16));
}
else
{
decEdit->setText("");
hexEdit->setText("");
}
}
#include "ByteConverterDialog.h"
#include <QtGui/QLabel.h>
#include <QtGui/QLineEdit.h>
#include <QtGui/QPushButton.h>
#include <QtGui/QVBoxLayout.h>
#include <QtGui/QHBoxLayout.h>
#include <QtGui/QGridLayout.h>
#include <QtGui/QIntValidator>
ByteConverterDialog::ByteConverterDialog()
{
QVBoxLayout* mainLayout=new QVBoxLayout(this);
QGridLayout* editLayout=new QGridLayout;
QHBoxLayout* buttonLayout=new QHBoxLayout;
mainLayout->addLayout(editLayout);
mainLayout->addStretch();
mainLayout->addLayout(buttonLayout);
QLabel* decLabel=new QLabel(tr("Decimal"));
QLabel* hexLabel=new QLabel(tr("Hex"));
QLabel* binLabel=new QLabel(tr("Binary"));
decEdit=new QLineEdit;
hexEdit=new QLineEdit;
binEdit=new QLineEdit;
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* exitButton=new QPushButton(tr("Quit"));
buttonLayout->addStretch();
buttonLayout->addWidget(exitButton);
exitButton->setDefault(true);
QIntValidator* decValidator=new QIntValidator(0,255,decEdit);
decEdit->setValidator(decValidator);
QRegExpValidator* hexValidator=new QRegExpValidator(QRegExp("[0-9A-Fa-z]{1,2}"),hexEdit);
hexEdit->setValidator(hexValidator);
QRegExpValidator* binValidator=new QRegExpValidator(QRegExp("[01]{1,8}"),binEdit);
binEdit->setValidator(binValidator);
setWindowTitle(tr("Byte Converter"));
QObject::connect(exitButton,SIGNAL(clicked()),this,SLOT(accept()));
QObject::connect(decEdit,SIGNAL(textChanged(const QString&)),this,SLOT(decChanged(const QString&)));
QObject::connect(hexEdit,SIGNAL(textChanged(const QString&)),this,SLOT(hexChanged(const QString&)));
QObject::connect(binEdit,SIGNAL(textChanged(const QString&)),this,SLOT(binChanged(const QString&)));
}
void ByteConverterDialog::decChanged(const QString& newValue)
{
bool ok;
int num=newValue.toInt(&ok);
if(ok)
{
hexEdit->setText(QString::number(num,16));
binEdit->setText(QString::number(num,2));
}
else
{
hexEdit->setText("");
binEdit->setText("");
}
}
void ByteConverterDialog::hexChanged(const QString& newValue)
{
bool ok;
int num=newValue.toInt(&ok,16);
if(ok)
{
decEdit->setText(QString::number(num));
binEdit->setText(QString::number(num,2));
}
else
{
decEdit->setText("");
binEdit->setText("");
}
}
void ByteConverterDialog::binChanged(const QString& newValue)
{
bool ok;
int num=newValue.toInt(&ok,2);
if(ok)
{
decEdit->setText(QString::number(num));
hexEdit->setText(QString::number(num,16));
}
else
{
decEdit->setText("");
hexEdit->setText("");
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks