QT/C++ – Accessing MainWindow UI from a different class

First off it’s a bad idea to create MainGame before you create your QApplication object. If you want to have your MainGame object globally available like this it should be a pointer: MainWindow *Game; int main (int argc, char **argv) { QApplication a (argc, argv); Game = new MainWindow(); Game->show(); int result = a.exec(); delete … Read more

Dynamic instantiation of QML objects?

You could simply: import QtQuick 2.0 Rectangle { id: root height: 500 width: 500 property string sc: ‘import QtQuick 2.0; Rectangle {width: 20; height: 20; color: “red”; Component.onCompleted: {x = Math.random() * parent.width; y = Math.random() * parent.height;}}’ Component.onCompleted: { for (var i = 0; i < 10; ++i) Qt.createQmlObject(sc, root, ‘obj’ + i); } … Read more

Two colours text in QPushButton

As s workaround you can use a label or text document to print the text you want. You should paint it to a pixmap and use the pixmap on your button : QPushButton *button = new QPushButton(this); QTextDocument Text; Text.setHtml(“<h2><i>Hello</i> “”<font color=red>Qt!</font></h2>”); QPixmap pixmap(Text.size().width(), Text.size().height()); pixmap.fill( Qt::transparent ); QPainter painter( &pixmap ); Text.drawContents(&painter, pixmap.rect()); QIcon … Read more

QMYSQL driver available but not loaded

We should check our driver first $ cd /opt/Qt5.2.1/5.2.1/gcc_64/plugins/sqldrivers then we can find some files Use the command below to check library $ ldd libqsqlmysql.so if you find the problem libmysqlclient_r.so.16 => not found it may be the library-dependency problem. After I did a little research on the Internet, there is a way would be … Read more

How to build the Qt-SQL-driver-plugin ‘QSQLCIPHER’ for SQLite-DB with SQLCipher-extension using the Windows/MinGW-platform?

How to build the Qt-SQL-driver-plugin ‘QSQLCIPHER’ for SQLite-DB with SQLCipher-extension using the Windows/MinGW-platform: Qt 5.4.0 for Windows/MinGW Download Qt Install including the sources e.g to C:\Qt\Qt5.4.0 OpenSSL for Windows Download Win32 OpenSSL v1.0.2a Download Visual C++ 2008 Redistributable Install Visual C++ 2008 Redistributable by executing ‘vcredist_x86.exe’ Install OpenSSL v1.0.2a by executing ‘Win32OpenSSL-1_0_2.exe’ Target directory e.g. … Read more

PyQt5 and QtGui module not found

When first trying pyqt4 and pyqt5 and the pycharm IDE I had many problems with imports. (although the imports had no prob running from IDLE) Eventually after much stuffing around, uninstalling and reinstalling, (including dependencies) the imports sorted themselves out. Did you install pyqt5 using an installer from the pyqt website? You must. Qt designer … Read more