Posted on

RED how to find a non-pointer variable


This means find the variable named “var” of type “VarType_t”

The variable must be defined on its own line because the ^\s* means find the line that starts with zero or more blank spaces or tabs.

The variable cannot be a pointer because the type is followed by [^\*]+ which means match any character except for ‘*’ one or more times

Posted on

How to use VS Code intellisense with Phaser 3

What is VS Code? It’s a nice text editor you can download for free here:

What is Phaser 3? It’s a nice game engine for web browsers you can download for free here:

How do you get VS Code to show Phaser documentation automatically in the editor? Create a text file named jsconfig.json in the root of your project folder that includes the Phaser types and your game code. The root of your project must contain folders that contain the code for Phaser and your game. For example, if your project folder is named “myProjectFolder” and your game code is stored in a folder called “src” and the Phaser 3 code is stored in a folder called “phaser” then here is your directory structure and jsconfig.json file’s contents:


  "include": [
  "files": [

After you create the jsconfig.json file and have saved it, close VS Code. The next time you open VS Code, select File->Open Folder and select your project root (“myProjectFolder” from our example”) and the Phaser information will be available after a short loading process completes.

Good luck!

Posted on

Qt project linker error for unresolved external symbol WinMain

Have you even received the following error after adding Qt to your Visual Studio project? The fix is easy but not what you would expect.

MSVCRTD.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol WinMain referenced in function “int __cdecl invoke_main(void)” (?invoke_main@@YAHXZ)

To fix it, Open Properties for the project then go to Linker -> System and change the SubSystem to Not Set from the drop down list. Make sure you do this for All Configurations.

That’s it. Back to work!

Posted on

How to override QTextEdit shortcut key bindings

The only way to override the default shortcuts while the QTextEdit has focus is to intercept the QEvent::ShortcutOverride event. There are 2 ways to intercept this event: 1. write an event filter 2. subclass QTextEdit and then override the virtual event(QEvent* event) method. I prefer this 2nd method (pun intended) because anything that changes the functionality of a widget should probably be its own class.

Here is an example of how I block the QTextEdit from using all shortcuts that start with Ctrl being pressed:

bool CustomTextEdit::event(QEvent *event)
    if(event->type() == QEvent::ShortcutOverride)
        QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
        if(keyEvent->modifiers().testFlag(Qt::ControlModifier) == true)
            // allow override of all Ctrl+ shortcuts
            return false;

    // normal procedure
    return this->QTextEdit::event(event);

Now that the QEvent::ShortcutOverride event has been used to cancel the shortcut, a QAction can be used to capture the shortcut calling setShortcut with the QKeySequence you wish to use. For example:


You can also setup the action directly in Qt Designer like this:

Posted on

RED – how to match lines that don’t contain a character

Time for another Regular Expression of the Day! Let’s say you are looking for all of the lines that don’t have a special character (like an ‘_’ underscore). Here is it:


Start of line, followed by characters that are NOT underscore, followed by End of line

It’s a little confusing that the start of line indicator is a carrot so if you think of it instead as the NOT the end of line indicator it helps

Posted on

Using grep on Windows to recursively find a C++ class definition in a header

There are so many grep examples out there but if you want to use grep on Windows to find something recursively in just one file type it can get a bit tricky.  Here is the quick 2 step process:

  1. get grep. you can find it here

  2. add path to grep into your PATH by opening the Windows start menu and typing “env” then selecting Edit environment variables
    Windows Environment Variables
  3. open a command prompt by opening the Windows start menu and typing “cmd” then press Enter
  4. enter a grep command.  for example, to find a class definition in all .h files it might be:
    grep -r --include=*.h "class WhereIsThatClass" *
Posted on

How to maintain aspect ratio for QPixmap as a QWidget instead of QLabel

There are so many times that I have wanted an easy way to show a QPixmap on a form while maintaining the aspect-ratio of the image that I finally sat down and made one.  The single header file can be downloaded here: Extract the .h file and add it to any Qt project. It provides all of the necessary features to show an image when and where you want it using the SpworksWidgetImage class.


// Don't forget to #include "spworkswidgetimage.h"

// SETUP //

SpworksWidgetImage* scaledImage = new SpworksWidgetImage();


// fill the widget to 75% of the widget's size

// place the image in the bottom right corner of the widget
scaledImage->SpworksWidgetImage_SetAlignment(Qt::AlignRight | Qt::AlignBottom);

// paint the background of the entire widget white before painting the pixmap

// place a hidden border around the widget to keep the image off the edge

Posted on

Moving Visual Studio Projects with Qt Integration

If you get an error like this:

The system cannot find the path specified.

or like this:

error MSB6006: "cmd.exe" exited with code 3.

Then you may need to just change your Qt Version under Qt Project Settings. The trick is that you must change from one valid Qt Version to another valid Qt Version. For example, if your current version is set to $(DefaultQtVersion) then you should change it to the explicit version entry. Make sure you actually apply the changed setting because otherwise nothing will happen. Once you have changed and applied the new setting, you can change it back and it may fix the problem.

Good luck!