Qt Signal Slot Cross Thread

Get the full on-demand video here: https://www.ics.com/webinars/qt-beginners-part-2-widgets

In the case of designing an application for an embedded platform instead of desktop, are there any differences in the approach?

Qt::AutoConnection: If the receiver lives in the thread that emits the signal, Qt::DirectConnection is used. Otherwise, Qt::QueuedConnection is used. The connection type is determined when the signal is emitted. Qt::DirectConnection: This slot is invoked immediately when the signal is emitted. The slot is executed in the signaling thread. Suppose I have an object A living in thread a and object C living in thread c. Object A has a signal sig1 which is connected to a particular slot of object C (default connection, which means in this case queued connection since it is cross-thread). Suppose thread a is running and object A emits signal sig1 twice before thread c runs. Cross Thread Signals/slots Default connection between objects of different thread affinity is Qt::QueuedConnection Sender's signal is serialized into an event Event is posted to the receiver's event queue Event is deserialized and the slot is executed Communication between threads is easy!

Yes. This is a large topic, but some of the considerations include the need to use a cross-compiler and deploying the code to a target system ensuring the application is suitable for the embedded system's RAM, filesystem storage, CPU, and GPU. Also, using a suitable user interface for the type of display (e.g. touchscreen) to ensure Qt is properly configured and built for the embedded platform including any hardware drivers that are needed.

Once I have installed Qt for Mac, how do I connect Qt to SQL server?

You should be able to do this using Qt's database support, but we would need more details, such as what database software you want to connect to.

Are QWidgets only for desktop applications or can they be used for mobile devices as well?

Qt Signal Slot Cross Thread

Widgets can be used on mobile platforms. They may or may not be suitable depending on screen resolution and whether you use widgets that work better when mouse-driven. Using style sheets or custom widgets you can make them better suited to smaller screens and touch input.

What is the easiest way to make a LED? For the LED just create a circle and control the color over a time period.

This ICS blog post may be helpful. It describes creating a custom LED widget: http://www.ics.com/blog/integrating-custom-widget-qt-designer

I installed and set up Qt open source on Linux. I also installed on Windows but Qt will not let me register under my Linux account. How can I register the Windows installation so I can use the Qt Maintenance Tool?

You should be able to use Qt on multiple platforms using your unified login account. If you have problems you should contact The Qt Company. See https://account.qt.io/support

Is it possible to create custom looking widgets?

Yes. Search the Qt documentation for topics containing 'Custom Widget' and you will find information and examples.

What output is created by Designer?

Performance

It is an XML-based .ui file which can be read by the uic tool to generate C++ code.

Can you swap menu bars back and forth in a QMainWindow?

It should be possible since you can get access to a QMainWindow's menu bar. There might be some platform-specific code needed if you want it to work properly on different desktop platforms (Mac versus Windows versus Linux).

How would you go about making custom styled widgets? E.g., a button that has some different border or a circular button?

Cosmetic changes can be handled with Qt's Style Sheet feature, which works similar to HTML's Cascading Style Sheets.

What is the advantage to using QWidgets over QtQuick/QML? And vice versa?

There are many considerations, some of which were covered toward the end of the presentation in Part 1 of this webinar series.

Are widgets used in development of Qt applications targeted for embedded systems?

Qt Connect Signal Slot

Yes, widgets can be used on embedded systems but QML is often a better choice if you want a touchscreen-driven interface. You can learn more about QML in part 3 of this webinar series.

Can you discuss using style sheets with widgets?

See the Qt documentation section titled 'Qt Style Sheets' for all the details.

Slot

Can the mouse cursor be manipulated with QCursor class?

Yes, the mouse cursor can be manipulated with QCursor class.

Not really a question but QApplication::setOverrideCursor(Qt::WaitCursor); and QApplication::restoreOverrideCursor();

Yes, this is a common task and can be hard to find in the documentation if you don't know what keywords to look for.

Qt Signal Slot Cross Thread

Qt Signal Slot Not Working

How would I develop a device with a touchscreen using Qt?

At a high level it is not dramatically different from a mouse-driven application but you need to start with a suitable user experience (UX) design. It can be done with (possibly custom) widgets but you may find it easier to use QML, which will be covered in Part 3 of this webinar series.

What is a shadow build?

Shadow building means building a project in a separate directory, the build directory. The build directory is different from the source directory. One of the benefits of shadow building is that it keeps your source directory clean, which makes it faster to switch between build configurations. Therefore, shadow building is the best practice if you need many build configurations for a single set of source files.

Cross

How do I access Qt Designer?

Qt Designer has 2 different forms, a stand-alone version which should be accessible in the same manner you access Qt Creator and an integrated version within Qt Creator itself. For the integrated version you simply need to be in a Qt Widget project and click the Design side-tab.

Will it be a problem to make the UI responsive using multi-threading after I have developed the UI using Qt Designer and have created slot/signal connections? Or is it better to create slot/signals connections from scratch by writing multi-threaded code in C++?

By default your application will all run in one thread, so you must ensure that you do not block the application for any significant period of time or the UI will not be responsive. Any time consuming code should be made event driven and/or run in a different thread. Signals/slots can cross threads and Qt has platform independent classes for creating and managing threads so you can implement this is a portable way.

How and where do you add your specific code to react to widget actions?

This is what signals and slots are all about. At a high level, widgets emit signals which you can connect to slots that you write to perform appropriate actions.

Can Qt Designer build the forms/outputs to different platform, for example Windows/Linux?

QWidget detects the OS the application it's running on and changes its look to fit in, by default. You can change it further if you want by creating a Qt Style Sheet and or palette.

Can Qt Creator be used on Android?

Yes, Qt Creater is compatible with Android. Android has support for building, deploying and debugging Qt applications.

How can I add a widget in Designer and have it initially hidden?

QWidget provides a setVisible member function which takes a Boolean argument.

Is it possible to manipulate the mouse icon? For example, to put some icons while dragging?

The class QCursor can help set the shape of the mouse icon when you want to change it.

How do I integrate the output from Designer in my code?

Every widget has signals and slots you can connect to that allow you to pass data between the front-end and the C++ code. The C++ code generated from Qt Designer by the uic tool is also typically stored in a header file that you #include in your application.

How do I stop a menu bar from being deleted when I set a new one in my main window?

Maintain a separate pointer to the old menubar so that when the mainwindow sets the new menubar, there is still a reference to it so it does not get deleted.

Is layout management available in QML?

Yes. That will be covered in our upcoming QML webinar.

Are there any plans to integrate Python into Qt designer for GUI development with PyQt, etc.?

Qt Designer uses XML-based .ui files and is not dependent on the programming language used for developing. PyQt supports using the .ui files created using Qt Designer and has a version of the uic tool that generates Python code. The Qt Creator IDE has some support for Python as well.

Are there widgets for touchscreens?

You need to have the Qt::WA_AcceptTouchEvents attribute set. From there you will need to reimplement the widget's event() function.