TheIdeasMan
TheIdeasMan

Reputation: 77

Qt Creator 2.8.1 Qt 5.1.1 Qt Designer Linux Show a new Form

I am a beginner with Qt - so hopefully this will be an easy question to answer. I have a reasonable amount of experience with C++, that part is not a problem

The purpose of my application is to do code generation, initially to make header & implementation files for classes. I quite like the Class wizard on Code::Blocks, but I reckon I can do a lot more.

I have a main Widget which has a tabWidget & some lineEdit's & some pushButtons. To preview what will eventually be in the file, I have created a new Form, with a TextBrowser in it. The new Form entry appears in the .pro file.

I would like to have the new Form displayed when I press the pushButton, & I am intending to write text in the TextBrowser based on the contents of the lineEdit's in the main Widget.

I have been looking through the documentation all afternoon, but most of the examples show either a main widget or a Form by itself. I have seen the example of the Class Wizard (which is nearly what I want to do), but I would rather a tabWidget interface. Being able to open a Form from a button is a pretty basic thing to be able to do.

For some reason, the examples page in my QtCreator help doesn't show any examples - previous versions had heaps of examples. Not sure why that is.

Do I have my terminology mixed up - should I have a Dialog rather than a Form? Not sure what the difference is.

Apologies in advance if all this is in the documentation somewhere, I seem to spend hours trolling through it, so maybe someone could provide some links - that would be great.

Upvotes: 2

Views: 340

Answers (1)

adnan kamili
adnan kamili

Reputation: 9445

Suppose the new form you created along with with header and cpp file is mynewform.h, mynewform.cpp and mynewform.ui

Now include mynewform.h in your mainwindow class,

and create an object of the class

mynewform myform;

In the clicked slot of pushbutton just type:

myform.show();

or

myform.exec(); //(if you want a blocking call)

Upvotes: 2

Related Questions