C++ (Qt)
qDebug() << QString::number(27, 2); // 11011
numconverter.h
C++ (Qt)
#ifndef NUMCONVERTER_H
#define NUMCONVERTER_H
#include <QtGui>
#include <limits>
class NumConverter: public QWidget
{
Q_OBJECT
private:
QLabel *output;
QSpinBox *input;
public:
NumConverter(QWidget *pobj = 0) : QWidget(pobj)
{
QVBoxLayout *layout = new QVBoxLayout;
QHBoxLayout *bottomLayout = new QHBoxLayout;
output = new QLabel(tr("Enter number..."));
output->setFrameStyle(QFrame::Box);
input = new QSpinBox;
input->setMinimum(std::numeric_limits<int>::min());
input->setMaximum(std::numeric_limits<int>::max());
QPushButton *button = new QPushButton(tr("Go!"));
connect(button, SIGNAL(clicked()), SLOT(inputReceived()));
bottomLayout->addWidget(input);
bottomLayout->addWidget(button);
layout->addWidget(output);
layout->addLayout(bottomLayout);
setLayout(layout);
}
~NumConverter()
{
}
public slots:
void inputReceived()
{
output->setText(QString::number(input->value(), 2));;
}
};
#endif // NUMCONVERTER_H
maain.cpp
C++ (Qt)
#include <QtGui/QApplication>
#include "numconverter.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
NumConverter nc;
/* nc.show(); */
return a.exec();
}