Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- hello.c -------------------------------------------------------------------------
- #include <iostream>
- #include <Wt/WBreak>
- #include <Wt/WContainerWidget>
- #include <Wt/WLineEdit>
- #include <Wt/WPushButton>
- #include <Wt/WText>
- #include "HelloApplication.h"
- #include "QtObject.h"
- // Needed when using WQApplication with Qt eventloop = true
- #include <QCoreApplication>
- using namespace Wt;
- HelloApplication::HelloApplication(const WEnvironment& env)
- : WQApplication(env, true)
- {
- /*
- * Note: do not create any Qt objects from here. Initialize your
- * application from within the virtual create() method.
- */
- }
- void HelloApplication::create()
- {
- setTitle("Hello world");
- root()->addWidget(new WText("Your name, please ? "));
- nameEdit_ = new WLineEdit(root());
- nameEdit_->setFocus();
- WPushButton *b = new WPushButton("Greet me.", root());
- b->setMargin(5, Left);
- root()->addWidget(new WBreak());
- greeting_ = new WText(root());
- b->clicked().connect(this, &HelloApplication::propagateGreet);
- nameEdit_->enterPressed().connect(this, &HelloApplication::propagateGreet);
- qtSender_ = new QtObject(this);
- qtReceiver_ = new QtObject(this);
- QObject::connect(qtSender_, SIGNAL(greet(const QString&)),
- qtReceiver_, SLOT(doGreet(const QString&)));
- }
- void HelloApplication::destroy()
- {
- /*
- * Note: Delete any Qt object from here.
- */
- delete qtSender_;
- delete qtReceiver_;
- }
- void HelloApplication::propagateGreet()
- {
- qtSender_->passGreet(toQString(nameEdit_->text()));
- }
- void HelloApplication::doGreet(const QString& qname)
- {
- greeting_->setText("Hello there, " + toWString(qname));
- }
- WApplication *createApplication(const WEnvironment& env)
- {
- return new HelloApplication(env);
- }
- int main(int argc, char **argv)
- {
- // Needed for Qt's eventloop threads to work
- QCoreApplication app(argc, argv);
- return WRun(argc, argv, &createApplication);
- }
- helloapplication.h -------------------------------------------------------------------------
- #ifndef HELLO_APPLICATION_H_
- #define HELLO_APPLICATION_H_
- #include "WQApplication"
- class QtObject;
- class QString;
- using namespace Wt;
- namespace Wt {
- class WLineEdit;
- class WText;
- }
- /*! \class HelloApplication
- * \brief The 'hello' application modified to use QtCore
- *
- * A sample application that uses objects from the QtCore library.
- */
- class HelloApplication : public WQApplication
- {
- public:
- HelloApplication(const WEnvironment& env);
- void doGreet(const QString&);
- virtual void create();
- virtual void destroy();
- private:
- WLineEdit *nameEdit_;
- WText *greeting_;
- QtObject *qtSender_, *qtReceiver_;
- void propagateGreet();
- };
- #endif // HELLO_APPLICATION_H_
- qtobject.h -------------------------------------------------------------------------
- #ifndef QTOBJECT_H_
- #define QTOBJECT_H_
- #include <QThread>
- class HelloApplication;
- class QtObject : public QObject
- {
- Q_OBJECT
- public:
- QtObject(HelloApplication *wt_, QObject *parent = 0);
- void passGreet(const QString&);
- Q_SIGNALS:
- void greet(const QString&);
- public Q_SLOTS:
- void doGreet(const QString&);
- void doShit();
- private:
- HelloApplication *wt_;
- };
- #endif // QTOBJECT_H_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement