This works in all cases where you call a class method on a NULL-pointer. The compiler does not (cannot) check for valid values of the pointer at compile time. It only looks at the type of the pointer, and as long as that checks out (in this case, the QDesktopWidget class does indeed have a function called screengGeometry that accepts 0 parameters) it will happily compile your code.
However, at runtime, this will most likely crash as soon as the code in that function accesses the class's data members. That is when it tries to dereference the "this" pointer, which in this case is NULL. The fact that your first example runs successfully simply means it does not access instance data, but only static or global data.
The second snippet is simply a completely different case, where you are trying to call a method as if it was static, while it is not. This results in the entirely correct and helpful error message you quote.
Ask yourself this though: What should the function return when you call screenGeometry when there is no instance to which it belongs. Both code snippets try to do something nonsensical.