Where Did My QDebug Output Go?

You start at a new place or on a new Linux distro coding away on your Qt project and suddenly find yourself asking; “Where did my qDebug() output go?” Lots of people are suddenly finding themselves in this boat. I fell into this boat after installing Majaro so I could work on the code for the last post. You will find a metric buttload of bad information.

In QtCreator you need to navigate to “Manage Kits” and scroll down to the Environment part.

Navigate down to Environment under Kits not the menu on right

You then need to click on “change.”

QtCreator kit environment qdebug output image
Add QT_LOGGING_TO_CONSOLE=1

Add QT_LOGGING_TO_CONSOLE=1 (no spaces) and click the OK button. That’s it. Every time you use that kit on a project your qDebug() output will print out like the used to.

There’s a lot of really bad solutions which aren’t contained to QtCreator itself out there. Don’t be duped into trashing your system.

Related posts:

So You Can’t Get Your Models to Work with QML?

MOC Parse Error at “std”

KDE Neon – Distcc and Qt

CopperSpice Experiments

QtCreator – No qmlScene installed

Qt book

CopperSpice Experiments – Pt. 2

Diamond is cross platform. It runs on Linux and other platforms supported by CopperSpice. There are some things I would like to try adding and donating back to the community.

  1. Themes – Right now you can just set individual colors but I would like to enhance that part to add the ability to save named sets of colors. I intend to try setting up a few from the world of Emacs that I like so there should be half a dozen default themes if I’m successful.
  2. A decent default font – The one thing they seem to have kept is defaulting to Courier New for the font. On Linux this looks horrible. I have done a bit of work on this subject with my XpnsQt project. You can even find other posts on this blog talking about such things. Choosing a decent monospaced font for the default should be easy. I just have to dig into that first load code.
  3. EDT keypad emulation – One of the things that compelled me to write my Gui Emacs book was the fact I was working on a GnuCOBOL book and that was the “best” IDE for it. What made me really start to like Emacs was both the GUI and EDT keypad emulation. The downside in Emacs is they inexplicably cannot map the NumLock key to GOLD. I had to map ScrollLock. Annoying. It became a real issue when I started logging into an actual OpenVMS computer using correct keypad emulation. Switching between the two was brutal.
  4. Compiling – There is support for a Tools menu and I think a command line type compile prompt would be nice. It would be especially nice if I can catch the output in another tab/window/dialog and get double click type support to take one to the offending line of the offending file.
  5. COBOL syntax – I don’t know about providing Area-A, Area-B and indicator column support, but adding basic COBOL syntax support should be doable.

That would kind of round out the editor for general editing. After that I’m a bit torn. There are things I would like to see, but honestly, after getting Diamond to that base, I think I would have to take a stab at a fork to create CsCreator much like QtCreator exists for the Qt project.

  1. Project file support – Maybe, just maybe, adding a project navigator window driven my CMake files since that is what CopperSpice uses.
  2. Debugging support inspired by Gede. I tried that debugger with GnuCOBOL the other day and kind of like it. Not the same license so cannot be merged in, but I can be inspired by the functionality and create my own. I suck at GDB command line debugging anyway so this would be a skill builder for me.
  3. A forms designer – Assuming CopperSpice has any support for .ui files. Probably not as involved a one as QtCreator as there is tons of stuff I just don’t use in there. Much of it seems to cause problems. If you can’t map all of your signals and slots in there you shouldn’t be able to map any of them.
  4. If I have full project file support I can look into those helpful typing suggestions and clang type nagging letting one know they typed something wrong/not-yet-defined.
  5. Function key to toggle from header definition to source implementation would be nice as well.
  6. Source control support – Yeah, that would be nice, but I have GitKraken.

<Previous-part Next-part>

QtCreator – no qmlscene installed

QtCreator, during various stages of its life, has spit the “no qmlscene installed” error out for quite a few people. If you are reading this you probably search for “no qmlscene installed” and landed here.

Since many of you reading this blog aren’t part of the Qt mailing list I thought I would share a question and my response. This problem comes up constantly and I’ve been bitten by it myself far more than I care to admit.

I just installed Qt Creator 4.5.2 from kubuntu apt sources.
It installed qmlscene + qt development files at the same time.
I can see clearly there is a qmlscene executable right next to qmake in
the same directory: /usr/lib/qt5/bin

How do I get rid of the “no qmlscene installed” warning?

“no qmlscene installed” happens due to many reasons

  1. Some fool used qml to create the welcome screen thus first introducing the problem. qml should never be used for anything.
  2. The 12 year old boys who crow about being “maintainers” of packages do little in the way of actual maintenance and testing. They simply remove anything someone complains about or which doesn’t compile.
  3. Ubuntu doesn’t test shit. They rely on the YABUs (Yet Another uBUntu) to provide fixes for them.
  4. Virtual Machines tend to hose QtCreator, or at least historically did.

Fix Number 1 – Move to KDE Neon or a non-Ubuntu Distro

Reason #1 was a point in time problem that will hopefully never exist again. That act of stupidity really did happen and it really got released into the wild. If memory serves it mostly showed up on KUbuntu. Assuming you don’t have a great investment in KUbuntu with installation, configuration,etc. Your simplest fix would be to move to KDE Neon.

The people who used to be creating KUbuntu but had __severe__ issues with the lack of testing and general state of life at/with Canonical jumped ship. They created KDE Neon based on a YABU core. Far more testing is done and they are migrating to their own repos. I say this because what Canonical has creating KUbuntu now reminds me of The Replacements.

And, because I’m typing this on KDE Neon where I have QtCreator 4.6.2-1 installed from the repos without the welcome screen issue. Like I said, KDE Neon does something which can actually be called testing.

If you are really in love with KUbuntu or married to it because it was documented via government filings as “the” development environment, you should know there are tons of “fixes” and “work arounds” out there.

Possible “Fix” #2

Assuming you are a good Qt developer and not allowing QML within 10,000 miles of your project, you can simply skip loading the Welcome screen. I do believe the virus known as QML has also wormed its way into the examples display pages, so you will have the same problems there.

qtcreator -noload Welcome

Please note the capital W on Welcome. Sorry, nobody has been polite enough to add -list to qtcreator so you could see a list of plugins to be loaded. They did add -profile, but, you really need to redirect that output to a text file you can search with Jed or some other editor for plugins.

Once you’ve determined this works, you can save yourself trouble by clicking on Help->About Plugins then scrolling down until you find Welcome to turn off the loading of it.

Possible Fix #3

Of course, you might want to determine your particular 12 year old boy didn’t just hose the pluginpath once again. From the -help output

-pluginpath <path>            Add a custom search path for plugins

start qtcreator from the command line providing the full path to the plugin and see if the problem also goes away.  If so

cd /
sudo find -iname qt.conf

cat out the file and look for plugins, here is what mine shows

roland@roland-I5-HP-Compaq-8300-Elite-SFF-PC:/$ cat ./usr/lib/x86_64-linux-gnu/qt5/qt.conf
[Paths]
Prefix=/usr
ArchData=lib/x86_64-linux-gnu/qt5
Binaries=lib/qt5/bin
Data=share/qt5
Documentation=share/qt5/doc
Examples=lib/x86_64-linux-gnu/qt5/examples
Headers=include/x86_64-linux-gnu/qt5
HostBinaries=lib/qt5/bin
HostData=lib/x86_64-linux-gnu/qt5
HostLibraries=lib/x86_64-linux-gnu
Imports=lib/x86_64-linux-gnu/qt5/imports
Libraries=lib/x86_64-linux-gnu
LibraryExecutables=lib/x86_64-linux-gnu/qt5/libexec
Plugins=lib/x86_64-linux-gnu/qt5/plugins
Qml2Imports=lib/x86_64-linux-gnu/qt5/qml
Settings=/etc/xdg
Translations=share/qt5/translations

Either your plugin isn’t in the correct directory, or the value here is incorrect. Common 12 year old boy problem. I must confess to not knowing  the syntax of or even if it is possible to have 2 different paths on one of these lines. You can set the environment variable QT_PLUGIN_PATH

Linux != Linux != Linux

Each and every distro decides “they have a better layout” when it comes to storing stuff. This then makes 90% of the “maintainer’s” job bulk editing scripts to change locations with each update. They miss stuff. QtCreator tends to be one of the most abused and least tested packages when it comes to “maintainers.”

KDE Neon will make your life a touch easier because they use Qt.

Related posts:

Where Did My QDebug Output Go?

MOC Parse Error at “std”

KDE Neon – Distcc and Qt

CopperSpice Experiments

So You Can’t Get Your Qt Models to Work With QML?

How Far We’ve Come – Pt. 8

This is where we begin to merge our discussion of distcc and the Raspberry Pi. The first thing I needed to do was actually get distcc installed on the Pi.

distcc install on Pi image
distcc install on Pi

Don’t forget the monitor so you can tell if things are working. I also created a ~/.distcc/hosts file.

localhost
roland-desktop
roland-HP-Compaq-8100-Elite-SFF-PC

After adding the previously mentioned make options to the project my out of the box attempt went like this:

First Attempt image
First Attempt

Notice the red bars? This means we had no access. I edited /etc/hosts to look as follows:

127.0.0.1	localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters
127.0.1.1       raspberrypi
192.168.1.132   roland-desktop
192.168.1.105   roland-HP-Compaq-8100-Elite-SFF-PC

Once the Pi had known hosts our build did just a smidgen better. Still not good, but better.

distcc after /etc/host change image
distcc after /etc/hosts change

Now we get that bluish color and some green. In the “compilation” window of QtCreator we now see things like this.

distcc[1234] ERROR: compile ../xpnsqt2/SplashDialog.cpp on roland-HP-Compaq-8100-Elite-SFF-PC failed
distcc[1234] (dcc_build_somewhere) Warning: remote compilation of '../xpnsqt2/SplashDialog.cpp' failed, retrying locally
distcc[1234] Warning: failed to distribute ../xpnsqt2/SplashDialog.cpp to roland-HP-Compaq-8100-Elite-SFF-PC, running locally instead
distcc[1233] ERROR: compile ../xpnsqt2/ReportBrowserDialog.cpp on roland-desktop failed
distcc[1233] (dcc_build_somewhere) Warning: remote compilation of '../xpnsqt2/

Everything worked flawlessly before because I had 2 different machines running the exact same version and bit distro. Compiling for the Raspberry Pi on a regular desktop requires a toolkit.

Next time I will install the toolkit on the 6-core AMD and get it working with the Raspberry Pi. Admittedly, most of you aren’t going to develop on your Pi, but, I want to see if it is possible to have the distcc server configured to support both the Pi and regular desktop builds without a bazillion tons of hacking. My suspicion is that distcc isn’t robust enough to know which tool chain to use. Once that server works for the Pi it won’t work for the desktop.

If somehow I magically get distcc to support both, then I really have to try adding the Android kit!

<Previous-part Next-part>

Related Posts:

QT Database book

AGILE book

Where Did My QDebug Output Go?

MOC Parse Error at “std”

KDE Neon – Distcc and Qt

CopperSpice Experiments

QtCreator – No qmlScene installed

So You Can’t Get Your Models to Work with QML?

How Far We’ve Come – Pt. 2

We need to establish a time frame before I start showing any code. Yes, you can go visit Source Forge to pull down what is there if you are well and truly desperate to view it. This portion is more about the journey than the code.

xpnsqt

The xpnsqt program was originally written around the time IBM sunset OS/2 which, according to this article, spanned the time frame between March 12, 2003 and December 31, 2004. Foundations of Qt Development came out in 2007 and C++ GUI Programming with Qt 4 came out in 2006. Both of them discussed QSqlDatabase. Ordinarily I would just hit the help key in QtCreator for QSqlDatabase. It would then take me to a help page which would say something like “feature/class was added in version blah.ha. Funny thing happened when I tried that today.

qtCreator image

Couldn’t find it on that page. Searched on-line in the 4.8 documentation and didn’t find any mention of when QSqlDatabase class was added. I don’t remember it being in Qt3 but I didn’t do that much with Qt3 because the message boards said Qt4 was going to be a night and day difference.

Point and Laugh

At any rate, now that most of you have some idea just how long ago this was and the fact it was my first “real” Qt program, it is time to let everyone point and laugh.

main.cpp

/****************************************************************************
 * Originally created by Roland Hughes at Logikal Solutions.
 * Project is being released under GPL2 license.
 *
 * At some point in the future either Logikal Solutions or Roland Hughes
 * may elect to publish a book with this original source code in it.  If
 * the book is written it will be part of "The Minimum You Need to Know"
 * book series.
 ****************************************************************************/
#include 
#include 
#include 
#include 

#include "XpnsLogonDialog.h"

int main(int argc, char *argv[])
{
    int i_x;
    QString qtDbName;
    QTime theTime = QTime::currentTime();

    QApplication app(argc, argv);

    {
        QString driverName = "QPSQL";

        //
        //  Set up information for driver and see if driver is available
        //
        qtDbName = "xpns" + theTime.toString("hhmmsszzz");
        QSqlDatabase db = QSqlDatabase::addDatabase(driverName, qtDbName);
        if (!QSqlDatabase::isDriverAvailable( driverName)) {
            QMessageBox::critical( 0, "Missing PostgreSQL Driver",
                                   "The Qt driver for PostgreSQL "
                                   + driverName
                                   + " is not installed.  You must install it before running this program",
                                   QMessageBox::Ok);
            db = QSqlDatabase();        //  reset to avoid warning
            return 0;
        }

        XpnsLogonDialog *xpnsLogonDialog = new XpnsLogonDialog( 0, qtDbName);
        xpnsLogonDialog->show();
        i_x = app.exec();

        qDebug() << "About to delete dialog";
        delete xpnsLogonDialog;
        qDebug() << "Dialog deleted, now clearing database";

        db = QSqlDatabase::database();  // clear connection to avoid error
    }  // end scope of logon dialog

    QSqlDatabase::removeDatabase(qtDbName);

    return i_x;
}

Looking at some of the comments in here brought back memories which were a long way from good. I’m sure many of you are freaked seeing the {} block enclosing the bulk of the program and the call to removeDatabase() outside of the block. When I saw the whole “clear connection to avoid error” comment it kind of all came back to me.

One thing I really hate about writing stuff like this for my blog, besides never getting paid for it,  is not being able to highlight code. There is probably some HTML markup tags which would let me set the background color, but the WordPress editor should make it a whole lot easier. Due to the way blog themes change the display of preformatted text I cannot even be sure line numbers will display.

The Logon Dialog

While I’m certainly not going to post all of the code in this series, we need to look at a couple more source files (kind of the worst) before we go too far in the discussion.

XpnsLogonDialog.h

/****************************************************************************
 * Originally created by Roland Hughes at Logikal Solutions.
 * Project is being released under GPL2 license.
 *
 * At some point in the future either Logikal Solutions or Roland Hughes
 * may elect to publish a book with this original source code in it.  If
 * the book is written it will be part of "The Minimum You Need to Know"
 * book series.
 ****************************************************************************/
#ifndef XPNSLOGONDIALOG_H
#define XPNSLOGONDIALOG_H

#include 
#include "ui_XpnsLogonDialog.h"
#include "Xpnsform.h"

class XpnsLogonDialog : public QDialog, public Ui::XpnsLogonDialog
{
    Q_OBJECT

public:
    XpnsLogonDialog( QWidget *parent, const QString &qtDbName);

    bool getConnectionStatus() { return m_connectionStatus;}
    int getTaxYear() { return m_tax_year;}
    bool useCalendarYear() { return m_calendarYear;}
    QString getActualDbName() {return m_actualDbName;}

private slots:
    void attempt_postgresql_logon();
    void on_userNameLineEdit_textChanged();

private:
    bool m_connectionStatus;
    void create_database( bool dbCreated);
    void ask_copy();
    void prompt_prior_year();
    void copy_prior_year( int year);
    bool  test_exists( int year);
    int m_tax_year;
    QString m_qtDbName;
    QString m_actualDbName;
    bool m_calendarYear;
    Xpnsform *xpnsForm;
};

#endif

Multiple Inheritance

Take a good look at that class definition. How many of you remember every class based on Qt and a UI file having to perform multiple inheritance? Come on, be honest! That all changed when the infamous “they” tried to make Qt usable by Java developers so they could finally abandon Swing. I and most others railed against that, but we lost. No, I won’t empty my colon on it again. You can buy a copy of this book if you want to read that rant. Let’s just say Java banned multiple inheritance and then had to bring it back with “interfaces.” They also banned the goto statement but the labeled break statement and a few other such things. The really bad parts in C and C++ existed for reasons. You can’t successfully remove the bad parts until you remove the reason for them.

Yes, if I don’t run out of time with this series I will rewrite the application from scratch using the more current approach to all things Qt. I believe you need to know where we came from because at some point you are going to encounter heritage code someone wants you to change without rewriting. If you don’t believe that you are either too young or haven’t been coding long enough. Every 1-2 years I get phone calls for a contract at a medical device company where they are looking for Qt 3 only. They have some device they want to make one small change in. If you rewrite they have to go through a very lengthy FDA approval process if the consultant just tweaks they can go through a much shorter and cheaper approval process. A rewrite means it is a “new device” while a change means it is an “updated/changed device.” No those aren’t the correct terms. I don’t remember the correct terms, but those work for the general audience.

Design due to QSqlDatabase “feature”

The convoluted design came about due to a “feature” with that version of Qt and Postgresql. In order to run like a mainframe/midrange application a database login dialog needed to pop up. Since I was going to release this as OpenSource I needed to have the information splash dialog pop up first so people too lazy to read a README.TXT would actually know something. First time users would be somewhat screwed. There was no way around having to manually enter categories. I didn’t want to ship with a predetermined set of categories. N year users would have it great because the login dialog would create the database for the tax year and offer to copy category information forward.

Our first “feature” reared its head during the first cut where I called the dialog exec() method. Even though QSqlDatabase was supposed to globally keep track of connections, when the dialog which created the database went away, so did the connection. In order to keep an entry you had to keep one reference alive. This left me with some really unenviable design choices.

  1. Pass a pointer to the db variable into the constructor of the dialog
  2. Pass string references for username and password and database year duplicating the connection code
  3. Derive from QApplication splitting all of the login functionality into methods within that class which would be executed when the event loop started.
  4. Doing something similar with a QObject class.

Our second and third “feature” reared its head when I didn’t have {} around the life of the db variable.  If one didn’t clear the database connection a runtime error would spit up in the terminal/debug window about object destroyed with active connection or something like that. Simply clearing the connection wasn’t enough, or at least it wasn’t instant enough. Calling removeDatabase() immediately after the clear with the db variable still in scope would cause more errors to be thrown about removing a database with an active connection.

Growing Pains Leave Warts

Yes, they were growing pains. Yes, most of these oddities have long since been cleaned up. Yes, this code still compiles and runs, I use it every time tax season approaches. Yes, you are going to encounter decade plus old code because it serves its purpose and rewriting isn’t free.

Many years ago I worked on a trading floor system for a stock exchange. The original “temporary” system was written in BASIC on a PDP 11 computer. Years later it was “temporarily” ported to the VAX hardware, then the Alpha, all the while the “permanent” trading floor system was being designed and a platform being chosen. This temporary system got pretty much rewritten when the U.S. stock market switched from trading in fractions to dollars and cents. That stock exchange got rid of its trading floor a few years ago. I’m told that “temporary” system went away with the trading floor but I would not be surprised to learn the automated portions of that system are what is running the exchange today.

Short Term “solutions” = Long Term Problems

Keep in mind that Y2K happened because “short term” solutions which made sense in the 1970s and early 1980s which were supposed to be replaced once storage and software became cheap enough were still in use near the year 2000. Read this page to learn what other Y2K like events are in your future.

Cast no stone at decade plus old code. We can always insult the ability of the developer but sometimes it is the ability of others which forced an ugly choice.

<Previous-part Next-Part>

Related posts:

Where Did My QDebug Output Go?

MOC Parse Error at “std”

KDE Neon – Distcc and Qt

CopperSpice Experiments

QtCreator – No qmlScene installed

So You Can’t Get Your Models to Work with QML?

QT Database book