Saturday, December 21, 2013

How to move Android SDK and NDK to a different location in Windows

Today, I've encountered the problem with using Android SDK with Qt Creator. The only message I got is "C:\Program" is not recognized as an internal or external command, so I've figured that the cause of this issue are spaces in the the path (C:\Program Files\Android\).

The moving process is very simple:

First, move your SDK directory into the destination folder (I will move entire Android directory to the root of C:\ drive, so my Android SDK path will look like C:\Android\android-sdk).

If you have only SDK, moving it is usually enough! However, if you have NDK installed, the next thing is to update you environment variables. Open Command Prompt and type control.exe sysdm.cpl. Open tab Advanced and click on Environment Variables.... Find ANDROID_NDK_ROOT variable, click Edit, and change it to reflect the new path (C:\Android\android-ndk in my case). Close all dialogs (by clicking the OK button) and you're ready to go!

Sunday, April 21, 2013

make_unique in C++14


One of the smallest additions is actually great in its impact. It’s make_unique:
  1. auto u = make_unique<some_type>( constructor, parameters, here );
The reason make_unique has important impact is that now we can teach C++ developers to mostly never use explicit new again. In C++11 we already could teach to never use raw pointers and explicit delete again, except in rare cases that are hidden inside a class in order to do something like implement a low-level data structure. However, we could not teach to never write new because although make_shared was provided to create a shared_ptrnewwas still needed to create a unique_ptr. Now, instead of “new”, write make_unique or make_shared.
With draft C++14, we can say simply: Don’t use raw pointers, new and delete, except rarely when implementing low-level data structures. Allocate with make_unique or make_shared, use weak_ptr where appropriate to break cycles, and don’t worry about dangling pointers in C++ again.


Sunday, April 14, 2013

Difference between NUL and NULL in C

From "Expert C programming - Deep C secrets" book:

The one "l" NUL ends an ASCII string,
Two two "l" NULL points to no thing.

If you check your include files, you will see definition of null as

#define NULL ((void*)0)

while NUL is first symbol in ASCII table (with value of 0).

Scrolling QScrollArea causes other widgets flickering

Today I've experienced a problem with QScrollArea which was placed besides another widget, like this:

 ________________    ______________
|                |  |              |
|                |  |              |
|                |  |              |
|                |  |              |
|   QWidget      |  |  QScrollArea |
|                |  |              |
|                |  |              |
|                |  |              |
 ----------------    --------------

Now, when my QScrollArea was scrolled into left, that caused part of QWidget that was overlapping with QScrollArea content to flicker.

To avoid this behavior, before scrolling (I am scrolling QScrollArea with buttons, but I guess connecting to the sliderPressed() and sliderRelased() of horizontalScrollBar and verticalScrollBar() should do the trick), you need to hide QScrollArea:

Monday, November 19, 2012

How to remove android NDK support from eclipse project

Today I've got stuck with pretty much weird errors in eclipse while trying to use ccache and android ndk-build. 

Apart from the fact that compiling was not successful, eclipse showed me dozens of errors which were complete nonsense. However, when I tried to compile project in cygwin console by calling ndk-build, everything well smoothly (well, not at the first time - see my next posts if you are having "Permission denied" error for accessing to some prebuilt libraries, or if you are having problems with undefined classes which are defined in std:: namespace).  

But, if I tried to run program in eclipse - project run failed because of NDK errors. So, I've found a simple solution:

a) All NDK code build using command line and ndk-build all.
b) Close eclipse, open project root, and delete .cproject file - you will remove C++ support from the project
c) Use eclipse for everything else.

Thursday, October 4, 2012

Where to keep Android application files

If you need to store configuration data, some resources, etc. in Android SDK, you should use assets folder for so. To access anything from it use AssetManager:


Also, take a note that assets are read-only.

Prevent form to blink when gets activate

In my previous post, I was telling you how to run one instance of the application and how to capture command line parameters from next runs. There were one problem, though - on every run, form was getting activate message and window started to blink. To resolve this, you need to handle WM_NCACTIVATE message to ignore Activate message:

protected override void WndProc(ref Message m)
    if (m.Msg == WM_NCACTIVATE)
        // Use this to make it always look inactive:
        m.WParam = (IntPtr)0;

        // Alternately, use this to make it always look active:
        m.WParam = (IntPtr)1;

    base.WndProc(ref m);