Quick tips

January 25th 2009 10:44 pm

I’ve rounded up some useful tips, none of which are really important enough to warrant a post just by themselves. So without further ado…

  • If you’re running kdesvn-build, you can use the --refresh-build option to force the given modules to be built with a clean build directory. But what if you didn’t want to do that for all of the modules on the command line? What you can do instead is create a file called .refresh-me in the toplevel of the module’s build directory (e.g. build/kdelibs/.refresh-me). When kdesvn-build rebuilds the module, if it finds that file it will perform the build process as if –refresh-build had been passed. Since –refresh-build involves deleting the build directory this is a one-time-only event. Next time you build everything will work normally.
  • Konqueror deserves several posts on its unique gems just on its own. But one thing I’ll mention is the address bar. There are two different keystrokes that I know of to quickly select the address bar: CtrlAlt - O will select the address in the address bar, handy if you just need to make a quick change to go to a different address. Ctrl - L on the other hand, will delete the text in the address bar first. I think this is a holdover from earlier days to be honest though, as since the URL is selected by default I can’t think of anything that Ctrl - L can do that is easier than using CtrlAlt - O. Update 2:One of the commenters pointed out that the selection buffer gets overwritten using Alt – O but is maintained with Ctrl – L. (i.e., when you middle-mouse-click to paste).
  • Do you use QDataStream? If so then it is imperative that you set the version of the stream. What I mean by this is that sometimes the binary representation changes depending on what version of Qt you are using. So a stream saved by a older version of Qt may be unable to be read using a newer version of Qt with the default version settings. QDataStream is backwards compatible; you just need to know what version to set the stream to. The process is described in the API documentation. Basically you need to set a specific version before writing and before reading. Some types (such as the integer types) are guaranteed not to change their representation, which you can use for versioning.
  • If you are a Qt programmer, then Thiago’s description of QString behavior is required reading.
  • Many people know that the C++ delete operator can safely be called on 0. Per the standard, this is also true for the delete[] operator, so you don’t need to check for null either way. (Of course, there are reports of compilers that screw it up for delete[], sometimes you can’t have your cake and eat it too).
  • And on that note, C++ has an interesting behavior that makes some variadic functions harder to use safely. To wit:
    • C has a NULL macro to represent the null pointer. Typically it would be along the lines of #define NULL ((void*) 0) or thereabouts. void * can be converted to any other pointer type so this is valid.
    • In C++ however, you can’t convert pointer types all willy-nilly. So the #define NULL ((void*) 0) doesn’t work. Instead you use plain 0, which C++ guarantees will be converted to the null pointer when used in a pointer context.
    • The key word here is “used in a pointer context”. Some variadic functions assume that the last parameter will be of a so-called sentinel value. It is up to the programmer to ensure they pass the sentinel correctly, and with the right type. For instance, many gstreamer varargs functions assume a null pointer will be the final argument.
    • If you use the NULL keyword things will work great in C and C++… if you’re on a system where int and pointers have the same size. On 64-bit systems this is not necessarily true.
    • The problem is that NULL is defined to plain 0 for C++. When 0 is passed as the last argument it is assumed to be of int type, not of a pointer type. For most 64-bit systems this will involve placing only 32-bits of 0 on the stack instead of the required 64-bits, and “undefined behavior” results.
    • The solution I used when I encountered this problem in KDE 3′s JuK was to simply define a GST_NULL that did the right thing. Other options are manually casting to a pointer type every time you use one of the vararg functions. But it’s something to keep in mind anytime you’re using variadic functions.
  • The upcoming revision to the C++ standard will include an actual null pointer instead of faking it with 0 and at least this kind of issue can be fixed. Some compilers have already included such a feature (including GCC) and so you may have never encountered this problem.

That’s enough food for thought for now though, hopefully this is enlightening reading for most. Update: The keyboard shortcut is Alt – O, not Ctrl – O.

Posted by mpyne under C++ & KDE & Programming | 8 Comments »

8 Responses to “Quick tips”

  1. Robin Identicon Icon Robin responded on 26 Jan 2009 at 04:41 #

    Thanks for the hint with the konqueror shortcuts.
    Being accustomed to Firefox I became slightly frustrated because ctrl-L always deleted the URL.
    Actually the other shortcut is Alt-O here (openSUSE 11.1) which behaves exactly like in Firefox. I wonder why that’s not the default for Ctrl-L…

  2. pinotree Identicon Icon pinotree responded on 26 Jan 2009 at 05:27 #

    What I use for focusing and selecting the location bar in Konqueror is F6, that should work almost everywhere out of the box (tested with Konq, IE6, FF3; it does not work with Opera, though).

  3. moltonel Identicon Icon moltonel responded on 26 Jan 2009 at 08:12 #

    The konq shortcut annoys me too, although others dont seem to mind.
    https://bugs.kde.org/show_bug.cgi?id=101631

  4. Giorgos Identicon Icon Giorgos responded on 26 Jan 2009 at 08:17 #

    >> Ctrl – O will select the address in the address bar
    >
    > What I use for focusing and selecting the location bar in Konqueror
    > is F6

    Thank you, thank you, thank you!

    I also agree this should be the default for Ctrl-L.

  5. mpyne Identicon Icon mpyne responded on 26 Jan 2009 at 08:44 #

    Robin: Thanks for reminding me of it being Alt-O and not Ctrl-O.

    pinotree: You’ll note that F6 even works in JuK… ;)

  6. Andrew Stromme Identicon Icon Andrew Stromme responded on 26 Jan 2009 at 11:01 #

    I use Ctrl-L when I need to paste something from my middle-mouse select buffer. Selecting then deleting sometimes clears my select buffer. It’s also another key command to hit.

  7. suy Identicon Icon suy responded on 26 Jan 2009 at 11:15 #

    F6 works on both Konqueror from KDE 3 and Konqueror from KDE 4 (at least on my system), but alt+O only works in KDE 4 (again, on my system).

    But oddly, in KDE4′s file dialog, the only way to focus the address bar is ctrl+L. :-(

    This is a bug, isn’t it? Or I’m missing something?

  8. mpyne Identicon Icon mpyne responded on 26 Jan 2009 at 13:30 #

    Andrew: Good point, sometimes I forget there is a separate selection buffer and clipboard in X11.

Trackback URI | Comments RSS

Leave a Reply