Skip to content

Instantly share code, notes, and snippets.

@yuwen41200
Created June 14, 2015 20:18
Show Gist options
  • Save yuwen41200/6aff6e4af97cab4c7866 to your computer and use it in GitHub Desktop.
Save yuwen41200/6aff6e4af97cab4c7866 to your computer and use it in GitHub Desktop.
Simple Qt Test
#include <QApplication>
#include <QLabel>
#include <QPushButton>
#include <QSpinBox>
#include <QSlider>
#include <QHBoxLayout>
int main(int argc, char *argv[]) {
QApplication *application = new QApplication(argc, argv);
// Part I
QLabel *label = new QLabel("This is a <b>Qt label</b> testing <i>window</i>.");
label->show();
// Part II
QPushButton *button = new QPushButton("Quit this Qt application immediately.");
QObject::connect(button, SIGNAL(clicked()), application, SLOT(quit()));
button->show();
// Part III
QSpinBox *spinBox = new QSpinBox;
spinBox->setRange(0, 130);
QSlider *slider = new QSlider(Qt::Horizontal);
slider->setRange(0, 130);
QObject::connect(spinBox, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
QObject::connect(slider, SIGNAL(valueChanged(int)), spinBox, SLOT(setValue(int)));
spinBox->setValue(35);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(spinBox);
layout->addWidget(slider);
QWidget *window = new QWidget;
window->setWindowTitle("Qt Window Title");
window->setLayout(layout);
window->show();
return application->exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment