LaTeX defines several conditional macros, with a syntax very different from the primitive
\if?<condition><true>\else<false>\fi
where \if? denotes any of the primitive conditionals. The conditionals defined by LaTeX have the form
\@ifsomething{<arg>}{<true>}{<false>}
or
\@ifsomething{<arg1>}{<arg2>}{<true>}{<false>}
Conditionals of the first kind are \@ifundefined and \@ifpackageloaded; among the second kind are \@ifpackagelater and \@ifpackagewith. The motivation for the distinction is that in the second kind we need something more to check a condition (the package name and an option name, for \@ifpackagewith).
The <true> and <false> code are executed respectively when the condition is satisfied or not. So
\@ifpackageloaded{geometry}
{\newcommand\qw{\itshape}}
{\newcommand\qw{\bfseries}}
is the answer. Either argument can be empty, of course.
You find an example of \@ifpackageloaded and some more information in Italian in this book (p. 78 for the main problem)
Note There is also \@ifdefinable<control sequence>{<true>} that has no "false" branch; it will execute the code <true> if the <control sequence> is undefined and raise an error otherwise (ignoring the <true> code).
source2e.pdf. – egreg Sep 5 '12 at 10:46