Results 1 to 3 of 3

Thread: Getting started with Qt Creator 4.6...

  1. #1
    Join Date
    Dec 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Getting started with Qt Creator 4.6...

    Hi all! I am a total noob with Qt, although I am a seasoned developer in many other environments. (Mostly Java I am afraid )

    But I have decided to try to learn Qt since I have some spare time...

    I have looked for, but failed to find, a walk-through of how to create some kind of "Hello World" application using Qt Creator + Qt Designer. There are various tutorials on the two tools separate, but they don't tell the full story of how to make them work together.

    So I have downloaded and installed the 4.6.0 SDK, and created a first "Qt GUI Application" using the New Project wizard.

    I am able to modify the UI and build and run the app without problems. Next step would be to have the UI actually perform some action.

    So I created a "Help > About..." menu item and added a "triggered" action to it, which gave me an on_actionAbout_triggered() slot in my MainWindow class, and the corresponding method stub in the mainwindow.cpp. Fine.

    Then I create a new Form of class QDialog which is to be the about box. Also simple. Fine.

    If I run a new build I now get a new ui header file for the new About box. Great.

    Except I can't seem to understand how I make the on_actionAbout_triggered()-method in the MainWindow class display the About box. I thought I should create a new instance of the QDialog that should have the MainWindow as parent, and then call .show() on this, or something similar.

    But how, exactly?

    It seems in the FormEditor window I have an object called AboutBox of class QDialog, but I can't seem to find any corresponding code that has been generated. The generated .h file has a class called UI::AboutBox but it is not a QDialog...

    Unfortunately the "Writing a Simple Program with Qt Creator" part in the QtCreator manual only has one form, so it doesn't help me here.

    /j
    Last edited by JesperWe; 15th December 2009 at 13:01.

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Getting started with Qt Creator 4.6...

    You'll have to work with the Ui::AboutBox in the same fashion as the ui in your main window is handled. Probably you could then get away with something like
    Qt Code:
    1. void MainWindow::on_thingy_triggered()
    2. {
    3. AboutBox *dialog = new AboutBox(this);
    4. dialog->setModal(true); // you probably want your about box to be window modal
    5. dialog->setAttribute(WA_DeleteOnClose, true);
    6. dialog->show();
    7. }
    To copy to clipboard, switch view to plain text mode 

    So, make a new class AboutBox, have its ui set up by Ui::AboutBox (look at MainWindow for an example) and create a new one as shown above.

    It's dry coded and untested, so there might be mistakes.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Dec 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Getting started with Qt Creator 4.6...

    Thank you. I got it figured out now. For other Newbie people hitting this thread, here is what I learned:

    - Creating a new form in Form Editor only creates the code for the UI object that sets up the form. It doesn't create any actual widget that displays it. This you will have to do yourself.

    This is what I ended up with after patching various tips together. Ui::AboutBox is the class generated by Qt Designer.

    Qt Code:
    1. void MainWindow::on_actionAbout_triggered()
    2. {
    3. QDialog *aboutBox = new QDialog;
    4. Ui::AboutBox ui;
    5. ui.setupUi(aboutBox);
    6. aboutBox->setAttribute( Qt::WA_DeleteOnClose, true );
    7. aboutBox->show();
    8. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 11:51
  2. Made changes to qmake. I want to share them, but I couldn't get started.
    By paulocarvalho_br_2009 in forum General Discussion
    Replies: 1
    Last Post: 25th May 2009, 15:41
  3. Replies: 5
    Last Post: 19th September 2008, 15:24
  4. Getting Started
    By Hockey in forum Newbie
    Replies: 9
    Last Post: 29th November 2007, 21:43
  5. Replies: 2
    Last Post: 30th March 2007, 08:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.