diff --git a/.gitignore b/.gitignore index 1a7edde..a35f132 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -/app /.rsconscache +/app +/build/ diff --git a/Rsconsfile b/Rsconsfile index 7c5e521..7be0c00 100644 --- a/Rsconsfile +++ b/Rsconsfile @@ -1,5 +1,19 @@ +class Moc < Rscons::Builder + def run(target, sources, cache, env, vars) + command = %W[moc -o #{target} #{sources.first}] + standard_build("Moc #{target}", target, command, sources, env, cache) + end +end + Rscons::Environment.new do |env| - sources = Dir["**/*.cc"] + env.add_builder(Moc.new) + sources = Dir["src/*.cc"] + env.build_dir("src", "build") + Dir["src/**/*.h"].each do |h_file| + moc_fname = env.get_build_fname(h_file, "_moc.cc") + env.Moc(moc_fname, h_file) + sources << moc_fname + end env.parse_flags!("!pkg-config --cflags --libs Qt5Core Qt5Gui Qt5Widgets") env.parse_flags!("-fPIE") env.Program("app", sources) diff --git a/main.cc b/main.cc deleted file mode 100644 index 7597418..0000000 --- a/main.cc +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include - -int main(int argc, char * argv[]) -{ - QApplication app(argc, argv); - - QHBoxLayout * layout = new QHBoxLayout(); - - QPushButton * button = new QPushButton("Press me"); - layout->addWidget(button); - - QLabel * label = new QLabel("Label"); - layout->addWidget(label); - - QWidget window; - window.setLayout(layout); - window.setWindowTitle("My Qt Application!"); - window.show(); - - return app.exec(); -} diff --git a/src/MyWindow.cc b/src/MyWindow.cc new file mode 100644 index 0000000..289e890 --- /dev/null +++ b/src/MyWindow.cc @@ -0,0 +1,24 @@ +#include "MyWindow.h" +#include + +using namespace std; + +MyWindow::MyWindow(QWidget * parent) + : QWidget(parent) +{ + QHBoxLayout * layout = new QHBoxLayout(); + + QPushButton * button = new QPushButton("Press me"); + layout->addWidget(button); + + QLabel * label = new QLabel("Label"); + layout->addWidget(label); + + setLayout(layout); + setWindowTitle("My Qt Application!"); +} + +void MyWindow::handleButton() +{ + cerr << "got a button press" << endl; +} diff --git a/src/MyWindow.h b/src/MyWindow.h new file mode 100644 index 0000000..213cf8c --- /dev/null +++ b/src/MyWindow.h @@ -0,0 +1,19 @@ +#ifndef MYWINDOW_H +#define MYWINDOW_H + +#include +#include +#include + +class MyWindow : public QWidget +{ + Q_OBJECT + +public: + MyWindow(QWidget * parent = 0); + +private slots: + void handleButton(); +}; + +#endif diff --git a/src/main.cc b/src/main.cc new file mode 100644 index 0000000..28616ef --- /dev/null +++ b/src/main.cc @@ -0,0 +1,15 @@ +#include +#include +#include + +#include "MyWindow.h" + +int main(int argc, char * argv[]) +{ + QApplication app(argc, argv); + + MyWindow window; + window.show(); + + return app.exec(); +}