Qt
proCreator: another helper for legacy Qt-projects
Ok, today at work I ran into the problem that for a Qt-project we have the code, the binaries and an awkward buildsystem (mpc). But I don’t want to process first the mpc and then fire up Visual Studio and wait for hours until the whole solution has been build. I want to use QtCreator! <3 So, there was never a real pro-file. The project consists of about ten classes, some forms and one ressource-file. Not much, possible to tinker it manually into a self-generated pro-file. Which can be processed then by QtCreator or qmake. (Hint "ls -X" is helpful for sorting by filetype.) But: why not delegate this to a small tool? First I thought about bash, then ... "maybe something better, like Python" ... and then ... why not Qt itself? So, please have a look at https://github.com/marcelpetrick/proCreator, which is half-way done. Outputting works. Just input-grabbing has to be implemented. Should be ready by sunday 🙂
Will keep you updated.
Qt: find the sender (aka: invoking signal) for a slot
Sometimes several signals lead to one single slot. Without any parameter. So you are stuck and can’t find out who was the ‘caller’.
But wait, there is a nasty hack to find it for those which are direct connections.
1 2 3 4 5 6 7 8 9 |
#include <QtCore/QMetaObject> #include <QtCore/QMetaMethod> [..] { //todom just for testing QMetaMethod const metaMethod = sender()->metaObject()->method(senderSignalIndex()); qDebug() << "invoking caller: name and signature:" << metaMethod.name() << "|" << metaMethod.methodSignature(); } |
QtScrobbler (final cut)
Just to close the topic: I finished what I planned for the forked QtScrobbler-project. I changed the workflow, so that if you did not provide correct credentials for your favourite submission-site (last.fm, libre.fm ..), then the progress-dialog will be closed and you will see immediately the error in the ui (not just log). Because before the user could wait until the cows come home – and I found this really annoying, especially when I set up QtScrobbler on a new system, mistyped or forgot to set the credentials at all.
Besides: also cleaned the code a little bit with the help of cppcheck 😉
The repository: https://github.com/marcelpetrick/QTScrobbler
All in all it was a nice experience: set up GitHub, clone the repository, work into a medium large project, try to fix an error without breaking the remaining functionality ..
I do not fully agree to the original code of conduct for style and includes. But as long as it is comprehensive ..
My first (?) offical fork?
I want to fix several smaller, but annoying issues with QtScrobbler. Originally hosted on sourceforge, but development was discontinued in 2013. I mean: it worked. I used it for years with my upgraded SANSA clips.
So I forked the project to github, upgraded the whole project to the current Qt-version (5.5) and fixed immediately some ‘klein-klein’. But now I am too tired …
Qt: normalized signal-slot-connections
While writing my last post I remembered a tool I run at least once for every project I touch (do, finish, ..): ‘normalize’.
Originally I stumbled about it while reading Marc Mutz’ blog. The downside is: currently the original download-location is not available anymore .. I will try to fix this.
The effect behind normalised signal-slot-connections is that for the whole project every connect will use the same style. No additional whitespace, no const, no unneeded variable-names, .. perfect.
Invoke it with “normalize –modify PROJECTPATH”. Without the flag it will just show the “to be changed sections”.
Never seen any downside effects.
edit: Working download-URL added!
Qt: find the libs (Linux)
I let synaptic install the libs, the qt-creator, the other stuff and their dependencies. Upon creating my first project I noticed NO kit was configured. Compiler was doable, but what about the libs? Tried this:
1 2 3 4 |
$ qtchooser -print-env QT_SELECT="default" QTTOOLDIR="/usr/lib/x86_64-linux-gnu/qt5/bin" QTLIBDIR="/usr/lib/x86_64-linux-gnu" |
part II: Remove multiple whitespace-lines from a file
I was so annoyed that the simple idea with sed did not worked like I wanted, that I wrote a short full-fledged Qt-appp for it. Code follows. Just compile the main.cpp. Usage is also explained in the header of the file.
I know it’s like to break a butterfly on a wheel, but I need this functionality since I don’t want to do such a boring task like code-styling by myself ..
Update: first version had a small glitch! Found after applying it to some bigger files.
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 |
//! @brief lessWhite should remove all multiple empty lines (newline, whitespace, tabs, spaces, ...) from the given input. //! Based on the standard POSIX channels stdin, stdout, stderr. //! usage like: $ ./lessWhite < input.txt > output.txt //! terminal output will look like: "removed 67 lines!" //! @author mail@marcelpetrick.it //! @version 0.02 (bugfix for "output had one additional newline at the end") //! //! history: 0.01: initial state #include <QTextStream> #include <QString> int main(int argc, char *argv[]) { Q_UNUSED(argc); Q_UNUSED(argv); QTextStream stream(stdin); QString output; //the combined stuff: no checks for overflow QString line; bool lastWasEmpty(false); int removedLines(0); bool isVeryFirstLine(true); do { line = stream.readLine(); bool const currentIsEmpty(line.trimmed().isEmpty()); if(currentIsEmpty && lastWasEmpty) { removedLines++; //do nothing } else { if(!isVeryFirstLine) //prevent the bug with the last line == double newline { output.append("\n"); } else { isVeryFirstLine = false; //reset now } output.append(line); } lastWasEmpty = currentIsEmpty; } while(!line.isNull()); //output QTextStream cout(stdout); cout << output; //print to stdout QTextStream cerr(stderr); cerr << "removed " << removedLines << " lines!\n"; //print to stderr } |
Replace the Sansa Clip (Clip+ or Clip Zip) firmware to make it scrobbleable
Work of 5 min (?)
Maybe even less if you know how to handle a mouse, the keyboard and a browser … 😉
First step is to exchange the firmware with Rockbox. A very good OSS mp3-player software for several different device kinds which enhances the hardware. You can even play Doom on your player!
- set the device to MSC-mode (MTP or Auto does not work)
- get the firmware for you device: Firmware thread at the Sansa-forums
- get and run the rockbox-installer
- select device and mount-point; pick the firmware-binary; select your options (bootloader and firmware yes; no games, no themes, no fonts …): “finish”, done
The second step is to enable scrobbling:
- got to your players settings (after restarting it and select “Settings > Playback Settings > last.fm log” with “enable”)
Play some tunes and afterwards connect you device to the PC and run QTScrobbler (note: Qt not QT! We are not in a hurry ;))
Qt Linguist: Extract all new strings
Task to achieve is: get all the new strings from the project, but the target user does not want to use Qt Linguist!
0. run lupdate (like always)
1. run
1 |
$ grep -C 2 "<translation type=\"unfinished\"></translation>" Language_EN.ts | grep "<source>" > ~/Desktop/newStrings.txt |
useless data pt. II
If you ever wondered how many times you compiled your project {today, the last week, ..} and got no answer: here is a clue.
Add the command “date >> someTextFile.txt” as custom command to QtCreator as build step before make is executed.
This will insert everytime you compile a new line with the current time into a textfile. Processing that data is your own task.
Small hint: if you are lazy and just want some alltime-stats use “wc compileDates.txt” 😉
Edit 20150407:
If you are just interested in the date, use this:
1 2 3 4 5 6 7 8 |
marcelpetrick$ cat compileDates.txt | cut -c 1-10 | uniq -c 14 Thu Mar 26 31 Fri Mar 27 16 Mon Mar 30 20 Tue Mar 31 48 Wed Apr 1 41 Thu Apr 2 16 Tue Apr 7 |