0

I have a Qt progam that I've made using Qt Creator. I made a .ui dialog (mainwindow.ui), and in the ui editor add the controls and slots. These end up creating methods in mainwindow.cpp eg.

void MainWindow::on_btnRunJohn_clicked()

In these methods, I'm accessing the controls directly to update them eg.

ui->txtConfigFileName->setText("Some text to put in the text box");

I know there are numerous ways to manage window dialogs in Qt (eg. QML, subclassing), but am wondering whether this approach is suboptimal, or limits things in some way. Is this a reasonable way to code in Qt, or is there a better approach to managing dialogs? I'm happy defining the controls up front ie. I don't need to add/delete controls at runtime.

2
  • surely it's reasonable... Commented Jan 26, 2013 at 8:27
  • Thanks CapelliC - I just hadn't seen the approach directly in some of the examples, and wondered whether there was something wrong with it. Will keep coding as is... Commented Jan 26, 2013 at 9:32

1 Answer 1

2

Actually if you want to change the behavior of the Ui, this is the way you have to go.

I suggest that you can use Multiple Inheritance, just like this:

class A : public QDialog, public Ui::A
{
    // class methods and members
}

This will help you to use the Ui widgets easly.

Sign up to request clarification or add additional context in comments.

1 Comment

By the way, the TextFinder example in Qt Creator gives a simple demonstration of this approach. It subclasses QWidget and contains a slot attached to a button that updates the ui.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.