Qt
Fixing ~crappy~ no-good Qt-includes
How to locate all includes of that style:
1 |
#include <QtWidgets/qcombobox.h> |
with proper
1 |
#include <QtWidgets/QComboBox> |
Fired up https://regex101.com/ and set it to PHP and created an expression, which matches:
starting with slash, then a q, then characters, then . then h
1 |
\/[qQ][a-zA-Z]+\.h |
(Replace & check has to be done by YOU ;))
Qt5: connect: How to use ‘connect’ in case the slot has less parameters than the signal
Task is to connect from one signal with one parameter to a slot with zero parameters. With the “old” Qt4-way of connect it works like this
1 |
connect(object1, SIGNAL(signal(int param)), object2, SLOT(slot())) |
But what if I want to use the type-safe Qt5-connects?
The documentation just mentions the cases with:
* connect to default parameters in slot
* and (for example) using the above-mentioned way of the string-based connect.
My idea was to use a lambda to fix this:
1 |
connect(object1, &Object1::signal, [this](int) { slot(); } ); |
But it turned out in in this thread that
1 |
connect(&object1, &ClassObject1::signal, &object2, &ClassObject2::slot); |
is possible! 🙂
First pull-request on github, yay!
Searched for a usable NTP-library, which assorts well with Qt and stumbled over qntp. While fiddling around I noticed in their source some opportunities to improve the code. So I cloned the repo, did them and created my very first pull-request for open-source 🙂
(Side-note: currently mostly Python-code is pushed due to the daily coding-challenge. But C++/Qt is still my carthorse.)
MPC: adding additional DEFINES
Some weeks ago I noticed how the qDebug()-output could be enriched, so that in bigger solutions with a lot of different “unknown” components a reported error could be immediately pinned. And you save writing always __FILE__ and __LINE__. Referres to this post.
But the problem was that with the mpc-buildsystem it was unknown to me how to force it to put this DEFINE into the vcxproj-files.
It can be done via the “macros”-statement!
So I worked on my Python-skills and wrote a short script which iterates the given path recursively and fixes all mpc-files by checking for the position of the line with the last closingbrace “}” and then it adds before that position the line. Of course, the experts know several thousand ways to improve that script – but I am currently happy with it. It works, it is debug-able (.sh, I look at you!) and I will use the skeleton also for some other tasks.
It can be found (like most Python-snippets) at: https://github.com/marcelpetrick/pythonCollection
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
import fileinput import sys import os #------------------------------------------ def addMacroToFile(filename, newStatement): #print("called addMacroToFile:", filename, determinePositionOfLastBrace(filename)) returnValue = "fail" posLastBrace = determinePositionOfLastBrace(filename) posCurrentLine = 1 for line in fileinput.input(filename, inplace=True): # add additional line in case of matching last brace if posCurrentLine == posLastBrace: sys.stdout.write(newStatement) sys.stdout.write("\n") # newline, else it would be put just before the brace returnValue = "success" sys.stdout.write(line) # prints without additional newline (on windows) posCurrentLine += 1 return returnValue #------------------------------------------ # return the position of the last brace. # possible improvement: in case of some malformed mpc: skip .. def determinePositionOfLastBrace(filename): lastPos = -1 position = 1 with open(filename, "r") as file: #has implicit close - which is nice for line in file: if line.__contains__("}"): lastPos = position position += 1 return lastPos # ------------------------------------------ # find all mpb/mpc files def fixAllFilesRecursively(path, suffix, newStatement): for dirname, dirnames, filenames in os.walk(path): for filename in filenames: full_path = os.path.join(dirname, filename) if full_path.endswith(suffix): print(full_path) wasSuccessful = addMacroToFile(full_path, newStatement) if wasSuccessful == "success": print(" modified :)") # prevent recursion into those subdirs with meta-data if '.svn' in dirnames: dirnames.remove('.svn') if '.git' in dirnames: dirnames.remove('.git') #------------------------------------------ #------------------------------------------ path = "D:\Repo_INS_RADARNX" suffix = "mpc" newStatement = " macros += QT_MESSAGELOGCONTEXT" # TODO possible improvement: prevent double application of the added macro .. fixAllFilesRecursively(path, suffix, newStatement) |
QT_MESSAGELOGCONTEXT: more detailed qDebug()
Add to your environment:
1 |
QT_MESSAGE_PATTERN="(%{file} : %{line}) :: %{message}" |
Windows: set either via “set” or via RapidEnvironmentEditor.
In case of a no-debug-build, add QT_MESSAGELOGCONTEXT to DEFINES in the pro-file.
(Open question: if there are just mpc/vcxproj-files, then how to trigger?)
related sources:
* https://woboq.com/blog/nice-debug-output-with-qt.html
* https://fecub.wordpress.com/2015/11/04/better-debug-output-using-qt_message_pattern/
* http://doc.qt.io/qt-5/qmessagelogcontext.html#details
Convert *.pro to *.vcxproj (qmake to Visual Studio-project)
0. Change this particualar line inside the *.pro:
1 2 3 |
# app is working for build and processing with qtcreator, vcapp is for visual studio #TEMPLATE = app TEMPLATE = vcapp |
1. run qmake against that pro-file
2. load the vcxproj with Visual Studio
edit: or do it with the original pro-file just like the wiki.qt.io suggests:
1 |
qmake -tp vc test.pro |
Cullendula
Small program to pick out the best shots of the vast amount of taken pictures per session (excursion). The name itself is a wordplay of the plant Calendula and the activity “to cull” (slang for sorting the photos).
url for the repository: https://github.com/marcelpetrick/Cullendula/
development time for fully usable version 0.1: one day
used technologies: C++ and Qt – my favorite ones <3
VisualStudio-Addin for Qt
The source for the current downloads: https://download.qt.io/official_releases/vsaddin/ (for MSVC 2013, 2015 and 2017), because I had to (again) search for the installation-files.
proper rename-scheme for digiKam
The Olympus-cam has no nice way to set an immediate scheme for the filename, so I transfer the files to the PC and fire up digiKam:
1 |
[date:yyyyMMdd-hhmmss]{unique:3} |
Fun fact: since it is based on KDE –> Qt, it also uses the same formatting for DateTime like Qt. Horay 🙂
Addendum: to fix the annoying “no klauncher found”-message and the invisible thumbnails after some certain apt-get-upgrades, just run
1 |
sudo apt-fast install kde-runtime |
again.
proCreator version 0.1 is ready!
url: https://github.com/marcelpetrick/proCreator
Clone, build (preferrably with QtCreator 4.x and Qt 5.9), run. A short howto in the readme describes how to use it.
After applying some restructuring, I got rid of some classes, simplified the code for reading the directory-content and for filtering. Kudos to the Qt-library!*
* Three slogans I like to stick to:
– Keep it simple (and stupid).
– Don’t re-invent the wheel.
– Functionality first.
Addendum: the proCreator was used now to revive two projects for which only source-code, but no “make-files” (pro, qbs, mpc, cmake ..) existed. It did its job 🙂