CS-280 Lecture

CS-280 Lecture

SE3910 Week 5, Class 3 Today In Qt Perhaps Physical Datarate Limits Lab: No Quiz SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1 GUI Toolkits Java

AWT Swing SWT Java FX C# WPF Windows Forms Silverlight GTK# C/C++

SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling Qt FLTK GTK Motif MFC 2 What makes a good toolkit? SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 3

Qt Features Fully object-oriented Consistent interfaces Rich set of widgets (controls) Have native look and feel Drag and drop Customizable appearance Utility classes OpenGL support Network support Database support Plugin support Unicode/ Internationalization

support GUI builder SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 4 Qt Widgets Java Swing Qt SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 5 Example QT Widgets

SE3910 Real Time Systems QT Built in Dialog Boxes File dialog Font dialog Color dialog Printer dialog SE3910 Real Time Systems Layouts Java FlowLayout GridLayout

BorderLayout BoxLayout BoxLayout Qt SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling FlowLayout (ex) QGridLayout BorderLayout (ex) QHBoxLayout QVBoxLayout 8

Layouts in Java and Qt Layouts in Java Layouts in Qt (in JFrame) (in QMainWindow) setLayout(layout) add(button)

layout->add(button) widget->setLayout(layout) setCentralWidget(widget) SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 9 Events/Signals Java Event

E.g. ActionEvent E.g. ActionListener How does Java initiate an event? Signal Event Listener Qt Slot

E.g. clicked() E.g. on_pushButton_clicked emit What Design Pattern is this? SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling 10 Custom Events in Java How do you register an event with an event source in Java?

How do you create your own event in Java? How do you fire an event in java? SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick 11 Custom Events in QT How do you register an event with an event source in QT? connect(button, SIGNAL(clicked()), qApp, SLOT(quit())); How do you create your own event in QT? signals: void clicked();

How do you fire an event in QT? emit progressNotification(1000 * seconds); SE-3910 - Dr. Josiah Yoder Slide style: Dr. Hornick 12 Threading qthreads (with corrections) qthreads Java java.lang.Thread No external jar needed Thread t = new Thread(r) t.start(); interface Runnable { void run(); } t.join();

#include (moc and friends take care of this) QThread *t = new QThread; moveToThread(t); // note here Object o; synchronized(o) { } /* Garbage coll. */ QMutex Avoid sharing memory entirely see code example ???? QObject (e.g. QWidget (e.g. QMainWindow)) connect the QThread ::finish() signal to a slot that checks if all thread s are done. 13

Useful if you are into Qt slots/signals == events A QThread should be used much like a regular thread instance: prepare an object (QObject) class with all your desired functionality in it. Then create a new QThread instance, push the QObject onto it using moveToThread(QThread*) of the QObject instance and call start() on the QThread instance. Thats all. https ://mayaposch.wordpress.com/2011/11/01/how-to-r eally-truly-use-qthreads-the-full-explanation / 14 SE-2811 Dr.Yoder Qts connect method http://doc.qt.io/qt-5/qobject.html#connect http:// doc.qt.io/qt-5/qt.html#ConnectionType-enum

SE-2811 Dr.Yoder 15 Qt Connection types http://doc.qt.io/qt-5/qt.html#ConnectionType-enum Constant Value Description Qt::AutoConnection 0 Qt::Direct 1 Connection Qt::Queued 2 Connection Qt::Blocking QueuedConnection 3 Qt::Unique Connection

0x80 (Default) If the receiver lives inthe thread that emits the signal, Qt::DirectConnection is used. Otherwise, Qt::QueuedConnection is used. The connection type is determined when the signal is emitted. The slot is invoked immediately when the signal is emitted. The slot is executed in the signalling thread. The slot is invoked when control returns to the event loop of the receiver's thread. The slot is executed inhe t receiver's thread. Same as Qt::QueuedConnection, except that the signalling thread blocks until the slot returns. This connection must not be used if the receiver lives in the signalling thread, or else the application will deadlock. This is a flag that can be combined with any one of the above connection types, using a bitwise OR. When Qt::UniqueConnection is set,QObject::connect() will fail if the connection already exists (i.e. if the same signal is already connected to the same slot for the same pair of objects). This flag was introduced in Qt 4.6. SE-2811

Dr.Yoder 16 Coding example. Exercise: Both the Java and Qt solutions will behave poorly if I start multiple threads. Predict how each solution will behave if I: Click start Click start // what happens? (For Java? For Qt?) Click stop // what happens? (For Java? For Qt?) SE-2811

Dr.Yoder 17 Week 10 Class 1 Communicating with Qt from a Non-Qt thread SE-2811 Dr.Yoder 18 Need invokeMethod http:// doc.qt.io/qt-4.8/qmetaobject.html#invokeMeth od http://doc.qt.io/qt-4.8/qmetaobject.html#Q_ARG

Code example: QMetaObject::invokeMethod(&objWithSlot, slotMethodName, Qt::QueuedConnection, Q_ARG(QString, QString(Hello!))) (But avoid smart quotes) Like SwingUtilities.invokeLater() SE-2811 Dr.Yoder 19 Sharing Memory If you pass a pointer through a slot, both sender and receiver will have a pointer to the same memory.

Some memory management care is needed to avoid issues here. SE-2811 Dr.Yoder 20 References EB: Derek Malloy, Exploring Beaglebone, Wiley, 2015 Laplante and Ovaska, Real-Time Systems Design and Analysis, Fourth Edition, Wiley, 2012 SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick 21

Recently Viewed Presentations

  • Survey Analytics Product Feature Highlights Unlimited Surveys Questions

    Survey Analytics Product Feature Highlights Unlimited Surveys Questions

    Features List Folder Management Solutions Survey Analytics Folder Management Solutions will ensure all survey data remains secure and gives you control over access to various folders for internal/external customers, vendors, and clients. Solutions include: -SSL Option: Enable SSL security on...
  • Arena Blended Connected (ABC) curriculum design Clive Young

    Arena Blended Connected (ABC) curriculum design Clive Young

    The ABC curriculum design method is an effective and engaging hands-on, card-based approach to curriculum design. student centered rapid curriculum development engaging academics in informed dialogue about the learning design or a review of programmesand modules
  • COMPUTER SYSTEMS An Integrated Approach to Architecture and

    COMPUTER SYSTEMS An Integrated Approach to Architecture and

    11.2.4 File Allocation Table (FAT) Divide disk into partitions. Each partition has a FAT. The directory just has a pointer into the starting sector entry in the FAT for each file. Less chance for errors than linked allocation. FAT becomes...
  •  Richard M. Ray, PE  Cybor Fire Protection Company

    Richard M. Ray, PE Cybor Fire Protection Company

    "Technical submissions" also includes, but are not limited to, studies, analyses, calculations, and other technical reports prepared in the course of the practice of professional engineering or under the direct supervision and responsible charge of a licensed professional engineer. THAT...
  • Institutions of Government

    Institutions of Government

    1883 - Pendleton Act - Civil Service System- Merit Based. Merit Based: Hiring based on exam scores, experience, or qualifications. ... April 2017 - Neil Gorsuch and the Nuclear Option. 20% of Presidential nominees have been rejected by the Senate.
  • Verbs - Weebly

    Verbs - Weebly

    Jump. Talk. hug. Connects the subject to the predicate. Linking Verb. Helping Verbs-there always be at least two!! Helping verbs help the main verb. Synonym is a verb phrase. Words that are ALWAYS Verbs. Am do was has. Is does...
  • UNHCR Representation in Ethiopia

    UNHCR Representation in Ethiopia

    Accounts the damaged and the sold: The fig. does not reflect the current reality . PV-Domestic home lighting. 12. 56. 70. UNHCR. 20. UNHCR and its partners should continue providing home light with raining and enforcing the implementation of the...
  • Maharashtra Dyslexia Association, Mumbai in collaboration with the

    Maharashtra Dyslexia Association, Mumbai in collaboration with the

    It's really a THERAPY as the kids go relaxed after they finish the session. All my students' parents have blessed me because of this program. The children are reading and are so confident. [email protected] HARSHITA SHARMA, PUNE The smile on...