This works fine for me:
QDialog *dialog = new QDialog;
Qt::WindowFlags flags(Qt::WindowTitleHint);
dialog->setWindowFlags(flags);
The most common way, however, is to pass the flags in the constructor:
QDialog *dialog = new QDialog(0, Qt::WindowTitleHint);
EDIT: I think there is a misunderstanding about the QFlags operators (see comments below). This example might clear it up:
Qt::WindowFlags flags(Qt::Dialog | Qt::WindowStaysOnTopHint);
qDebug() << flags.testFlag(Qt::WindowContextHelpButtonHint); // false because the flag hasn't been added
flags = flags | Qt::WindowContextHelpButtonHint;
qDebug() << flags.testFlag(Qt::WindowContextHelpButtonHint); // true because it has been added
flags = flags & ~Qt::WindowContextHelpButtonHint;
qDebug() << flags.testFlag(Qt::WindowContextHelpButtonHint); // false because it has been removed
The penultimate line of code removes Qt::WindowContextHelpButtonHint
from flags
. It does not add a "negative" flag.
At least that is my understanding.