title: Set QLineEdit focus in Qt
body: <p>I am having a qt question. I want the QLineEdit widget to have the focus at application startup. Take the following code for example:</p>
  
  <pre><code>#include &lt;QtGui/QApplication&gt;
  #include &lt;QtGui/QHBoxLayout&gt;
  #include &lt;QtGui/QPushButton&gt;
  #include &lt;QtGui/QLineEdit&gt;
  #include &lt;QtGui/QFont&gt;
  
  
   int main(int argc, char *argv[])
   {
       QApplication app(argc, argv);
  
       QWidget *window = new QWidget();
       window-&gt;setWindowIcon(QIcon("qtest16.ico"));
       window-&gt;setWindowTitle("QtTest");
  
       QHBoxLayout *layout = new QHBoxLayout(window);
  
       // Add some widgets.
       QLineEdit *line = new QLineEdit();
  
       QPushButton *hello = new QPushButton(window);
       hello-&gt;setText("Select all");
       hello-&gt;resize(150, 25);
       hello-&gt;setFont(QFont("Droid Sans Mono", 12, QFont::Normal));
  
       // Add the widgets to the layout.
       layout-&gt;addWidget(line);
       layout-&gt;addWidget(hello);
  
       line-&gt;setFocus();
  
       QObject::connect(hello, SIGNAL(clicked()), line, SLOT(selectAll()));
       QObject::connect(line, SIGNAL(returnPressed()), line, SLOT(selectAll()));
  
       window-&gt;show();
       return app.exec();
   }
  </code></pre>
  
  <p>Why does <code>line-&gt;setFocus()</code> sets the focus on the line widget @app startup only if it is placed after laying out the widgets and if used before it's not working?</p>