Opening projects and getting started
-
@Bryan-Kelly said in Opening projects and getting started:
Windows 11, Qt 6.6.0, Qt Creator 12.0.2
Open a project, a very simple one as I am just starting, and open mainwindow.ui. In the list of controls I don’t recognize anything that looks like something to add a new dialog. My searches for “how to create a new dialog in qt creator”, and other similar searches do not provide the results I need.File->New File->Qt->Qt Designer Form Class.
This will add a new C++ class with a connected .ui form for your dialog. You can design and prepare your dialog here. Then to display it, in your main window you need to:
- include the dialog header file
- in button slot reacting to
clicked()
signal, instantiate your dialog (withnew
) - don't forget to call
show()
orsetVisible(true)
on your new dialog instance
Should work :-)
From the top dialog I want the ability to open one of several sub dialogs with a button for each one. How is this easily accomplished?
Repeat steps outlined above.
Unless you want one of the built-in dialogs, like file saving or opening dialogs. See: https://doc.qt.io/qt-6/qfiledialog.html#static-public-members
And if I may, a second question: Getting started is taking more effort than it should, for me that is. Would I be out of line to offer to pay someone to create a starter project for me? I would like more than is reasonable for a few threads in a forum.
Suggestion: make this part of your post bold and also post a new thread in Jobs subforum. It is not out of line, I would love to help myself but I'm crazy busy this and next month :-(
-
-
@sierdzio I think the instructions were followed but I don't get a dialog displayed. Here is mainwindow.cpp
#include "./ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}MainWindow::~MainWindow()
{
delete ui;
}
// the new class is named quadratic
void MainWindow::on_open_quad_clicked()
{
quad_dialog = new( quadratic ); // << breakpoint here
}It builds with no error and a breakpoint is set as shown. A pushbutton was added in mainwindow.ui, it is clicked, the breakpoint was reached. Step over and next line is the closing brace of the function. There is no dialog displayed.
I suspect I have not created the dialog itself, just a class that will contain the dialog.
Is my error apparent? What are the steps to create the actual dialog to be displayed? -
@Bryan-Kelly looks good so far. Perhaps the dialog is hidden by default, just call
open()
on it.quad_dialog = new quadratic(this); // remember about parent-child relationship quad_dialog.open();
-
@sierdzio The variable is a pointer so this is required:
quad_dialog->open();
and the response is:
No member named 'open' in 'quadratic'Interesting, Qt will not allow us to copy the error text so it can be pasted into a forum, or anything.
In case I am missing something really important. I am trying to create a dialog, something I think is or should be a standard item. And it should have a flock of already existing capabilities. Is dialog the right name. How do I instantiate a dialog and open it from the default top dialog of a simple project.
-
@Bryan-Kelly said in Opening projects and getting started:
No member named 'open' in 'quadratic'
So can you please show the definition of your
quadratic
class? You ask about this/opening a dialog, but you have not shown us where you even have a dialog/QDialog
, only your main window stuff. And as it stands it is hard to see how your code could even compile, where is a header file included which definesquadratic
? -
@JonB The top level file list looks like this. (hopefully)
File quadratic.h and .cpp were created automatically while following the instructions of this thread. The .h file contains this.
#ifndef QUADRATIC_H #define QUADRATIC_H class quadratic { public: quadratic(); }; #endif // QUADRATIC_H
&&&&&&&&&&
The quadratic.cpp file contains this.#include "quadratic.h" quadratic::quadratic() {}
&&&&&&&&&&&&&& (marks the end of something for easy reading)
I have not tried to do anything within that class, just display a dialog.
File mainwindow.h contains this.#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include "quadratic.h" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); private slots: void on_open_quad_clicked(); private: Ui::MainWindow *ui; quadratic* quad_dialog; }; #endif // MAINWINDOW_H
&&&&&&&&&&&&&&&&&&&&&&&&
And mainwindow.cpp contains this#include "mainwindow.h" #include "./ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_open_quad_clicked() { quad_dialog = new( quadratic ); // quad_dialog->open(); // tried to add this but it does not exist. }
&&&&&&&&&&&&&&&&
It builds, runs, and displays the top dialog with the single button titled “Open Quad”
The files named hypotenuse.h and .cpp are essentially a copy of quadratic, but nothing has been done with them yet.
Again, the goal is to start with the main dialog and open a second and third dialog. There is nothing to do in those dialogs, just get them to open and display on my monitor.
Is there anything else needed? -
@Bryan-Kelly
Please use the forum's Code tags (</>
button) for blocks of code.@sierdzio took your
quad_dialog = new( quadratic );
to mean thatquadratic
was a class derived fromQDialog
, per the name of the variable. Naturally that does not have anopen()
method like a dialog would.You don't get a dialog displayed because I cannot see anywhere you have created a
QDialog
. So I don't know what you are expecting.You can create a
QDialog
in code if you wish, and callexec()
on it. If you want to design it in Designer you need to follow the steps @sierdzio enumerated for you. There are plenty of examples on the web and in the documentation, and there is nothing special about designing a dialog versus another widget type. -
@JonB The key item appears to be QDialog, which was not mentioned until the fifth post or so. The steps noted by @sierdzio did not do the job. And just in case, I wrote out the instructions in a step by step procedure which is repeatable.
Having "QDialog" in hand, found a video and am able to use a button in the original dialog and open a new one. This is part way to what is needed.
I presume that with this QDialog code must be written to place every object/tool within the dialog. In my project it does not show up in a manner similiar to "mainwindow.ui", meaning the user cannot drag and drop controls on to it.
Seems to me there should be a tool that works or is used in a manner that is analogous to the object/file/something-else? as the item mainwindow.ui. Being explicit, I am hoping there is a method to drag and drop controls onto the new dialog rather than writing the code to add each item, place it exactly, size it exactly, etc.
Does that ability exist?
-
@Bryan-Kelly
You can certainly design a dialog in Creator/Designer, just like you did for yourMainWindow
. The steps @sierdzio wrote are exactly what you need to do. Saying "The steps noted by @sierdzio did not do the job." does not help know where you had a problem, and your posted code shows no sign of having had a dialog added to it. Onlyquadratic
, which is not a dialog. And I see no sign of aquadratic.ui
being added to your project, just like themainwindow.ui
which shows there. -
@JonB This post had two parts. First, I recognize that what I need may well exceed what is reasonable for a thread. I placed a post in the jobs section here: [link text]([https://forum.qt.io/topic/155638/need-help-with-startup-project-my-qt-first-project?_=1711680558425](link url))
Second, I tried working this and wrote what I did one step at a time. Here is a recap of the goal and the steps that I understand from the posts on how to accomplish those goals. Where did I go wrong? What did I miss?
The goal is to create a simple Qt project with multiple dialogs. Specifically, the main dialog is to have the ability to open additional dialogs. The environment is Windows 11, Qt Creator 12.0.2, and Qt 6.6.0.
I created this in MS Word with numbered lines and indented sub sections. the goal is to prevent a long monolithic description and to provide step numbers that can be referenced when addding advice. I hope the formatting helps some amount.
- File -> New Project
- Create a simple project
a. Application (Qt) -> Qt Widgets Application -> Choose
b. Select your name and location, Next (below "i" is implied indent again)
i. This was named “three_dialogs_02”, the location is defaulted to the same name, noted for possible future use.
c. CMake -> Next
i. Because this beginner does not have sufficient knowledge for any other selection.
d. In dialog Qt Widgets Application, change to suit, but no changes made on this project, Next
e. Translation File -> Next, no changes
f. Kit Selection -> enable Select all kits, because this beginner is now aware better options, Next
g. Project Management -> Finish, no changes
h. Build and run, displays a blank dialog - Create a new dialog, or maybe several
a. File -> New File -> C/C++ -> C++ Class -> Choose
b. In dialog C++ Class, Name it.
i. Just for future reference, the name is quadratic
c. Base Class. There are six options here. Not having a specific reason to change, take the default of <Custom>
d. Not knowing better choices, skip all the options. ??
e. Path: This defaulted to …\three_dialogs_02, left that unchanged -> Next
f. Dialog Project Management, no changes, Finish
g. There are two new files, quadratic.cpp and .h - Provide the ability to open the new dialog
a. Eidt mainwindow.ui
b. Add a Push Button
i. Set its text to: Open Quad
ii. Set its objectName to: pb_open_quad
iii. Right click it and select: Go to slot…
iv. Select QAbstractButton -> clicked -> OK
v. This opens file mainwindows.cpp and has created function:
vi. void MainWindow::on_pb_open_quad_clicked() { }
vii. edit in show() - Build and run
a. the main dialog opens with the new button
b. Click button Open Quad, nothing happens.
c. Close, put breakpoint in new function on_pb_open_quad_clicked() as show():
d. Start debug
e. Click button Open Quad
f. The breakpoint a show() is caught.
g. Press F10 three times and it steps out of the function into moc_mainwindow.cpp
h. Stop here. The pushbutton works, but the new dialog does not.
The new dialog is not shown. There is no new file similar to mainwindows.ui, that represents the new dialog so controls can be added to it in a drag and drop fashion.
Please advise, what did I do in error? What obvious step did I miss? -
@Bryan-Kelly said in Opening projects and getting started:
a. File -> New File -> C/C++ -> C++ Class -> Choose
b. In dialog C++ Class, Name it.This creates a plain C++ class, nothing visual, which is what you ended up with. You are supposed to be creaking a dialog, something like when you designed the main page. @sierdzio wrote:
File->New File->Qt->Qt Designer Form Class.
I'm sure if you went into the Help in Creator it would cover this. I don't necessarily have the same version of Craetor so don't ask me what the wording is, you are supposed to figure this out. Look around the choices of new items available.
-
@JonB I restate my request in different words.
Create a Qt Widgets application.
Under Source Files is the file: mainwindow.ui
When this file is opened the user can drag and drop controls.
Here is the request:
What are the steps to create a new dot ui file into which the user can drag and drop controls? Make the name quadratic.ui -
@Bryan-Kelly
I already answered, and so did @sierdzio . Pick the right new item type to add to the project. Not a plain C++ class, rather a Qt widget. -
@JonB said in Opening projects and getting started:
The question has not been answered. I wrote down the steps one line at a time, posted, and that post was essentially ignored.
After the project is initially created, what steps are needed to use Qt Creator facilities and create the new file quadratic.ui? The dialog is to be such that standard controls, push buttons, text edits, etc, can be dragged and dropped onto it and used in the code.I have searched and have not found the solution. If someone can provide a better search phrase I will use it.
-
@Bryan-Kelly said in Opening projects and getting started:
Qt Creator facilities and create the new file quadratic.ui? The dialog is to be such that standard controls, push buttons, text edits, etc, can be dragged and dropped onto it and used in the code.
Maybe rephrase the above.
In general, forums and this one is no exception, posts gets boggled down in (personal views) , expressions and terminology.You can build application using main window.
You can the add a dialog to it.You can "drag and drop " widget ( user interlace "object" )
into the dialogue DURING construction / coding using the dialog_X.ui file- utilizing QtDesigner tool.This is the way I read / interpret your post
you want the user to be able to "drag and drop" such widget ( from where he get is ?) during RUN TIME.
Is that correct (assumption) ?
-
@AnneRanch said in Opening projects and getting started:
You can the add a dialog to it.
And that is the key phrase.
What are the steps to add the dialog? Let's call the dialog quadratic. To clarify, after adding the dialog I am "expecting" that within "Header Files" there will be the file: quadratic.h Within Source files there will be quadratic.cpp and quadratic.ui (Those names seem logical to me and the exact name is not a requirement.)
When file quadratic.ui is opened for editing, I can drag controls into it, such as push button and line edit. the behavior should be the same as what I find for mainwindow.ui.
This is all during application construction time, not during run time. Then I can add buttons in mainwindow.cpp so that during run time I can open the new dialog and populate fields within the dialog, using appropriate procedures of course.
That one step, adding the dialog, is now the heart of this thread.
-
@Bryan-Kelly said in Opening projects and getting started:
I wrote down the steps one line at a time, posted, and that post was essentially ignored.
And you was told several times already what you need to select to create a dialog (File->New File->Qt->Qt Designer Form Class), instead you wrote:
File -> New File -> C/C++ -> C++ Class -> Choose
As already explained here - this creates a plain C++ class, not a widget/dialog. Why don't you follow advises?
-
@Bryan-Kelly said in Opening projects and getting started:
The question has not been answered. I wrote down the steps one line at a time, posted, and that post was essentially ignored.
You wrote your steps. Far from ignoring you I actually quoted from your own steps, verbatim:
a. File -> New File -> C/C++ -> C++ Class -> Choose
b. In dialog C++ Class, Name it.
See that in the steps you wrote? So how come I quoted your step and what you needed to correct it if I was ignoring you? And then I told you this is wrong. I quoted from @sierdzio who wrote you need to pick:
File->New File->Qt->Qt Designer Form Class.
I also suggested if you go into Creator's help at this point I would have though it would explain the various new item choices available from File -> New File -> C/C++. So you would know which one to pick:
Pick the right new item type to add to the project. Not a plain C++ class, rather a Qt widget.
So, instead of saying your post/question has been ignored why don't you actually follow or respond to my responses? It is simply you who are doing the ignoring. You do not have keep repeating what it is you want to achieve, we all understand that. We know why you are getting it wrong by picking a new "C++ class" as the item, and we have told you that is not the right one to pick, you need to pick the one which offers to create a new Qt widget, which will give you the "surface" where you pick things and drag them onto it to design your widget/dialog.
Note that I use Creator 6. You are using Creator 12. That isa different version from mine. So my screenshots may not match exactly what you see, but hopefully they will be close. Unless you only want screenshots from somebody using the exact same version of Creator as you have.
From Creator, menu File > New File or Project...,
On the left you have C/C++ highlighted and C++ Class selected to the right. The info panel at the right tells you this will add a C++ header and source file to your project. That is what you are picking. This is wrong for what you want. If you pick it you will get the plain C++ class you have had so far. This is not what you want. It is wrong. If you continue with that you will not get what you want. You have to change your choice to the one you need. If you choose to ignore this you will not solve your issue. You have to do something else.
Move your mouse with your hand. In the left hand area move it to the item which says Qt. You want something Qt-specific for designing widgets, so that is what you need to pick.
Now have a look at the choices in the middle. Any of them look possible? What about Qt Designer Form, since you want to create something in Qt Designer and if you read earlier you have been told repeatedly to pick this. Click on Qt Designer Form with your mouse. Then move your mouse to the Choose... button in the bottom right of this dialog and press the mouse to click.
From then on as you work through the wizard hopefully you can make your own choices for what you want. Take the time to look at the choices before you pick one.
Is that enough for you, or still not clear enough? Do you still think I am ignoring your question? Did we not say from the outset that you needed a new Designer form? In all the years I have been here nobody has had any trouble picking a new Designer form to add or asked about it.
-
OK, you "experts"
...cut it out...
The way you are getting into "advices" is too familiar to me.
Stick with technology and STOP the innuendos.
You can help and be more constrictive by skipping the lecturing, unless you have background in teaching.I would actually like to see a Qt published example of the task the OP is trying to do - main application ( main window) with dialog as sub window.
Unfortunately I have not found one yet.
What the OP is trying REALLY needs a solid foundation, mainly because his vision of manipulating the dialog and communicating between main and dialoog , is the VISIBLE part of the iceberg and without good knowledge what " lays hidden in water part ", it does not look much fun to code.
PS
I am using "simple terminal" Qt example , it has similar layout (main window with dialogs ) , but I would not recommend that as first Qt project.PPS
OP - take a look at thishttps://stackoverflow.com/questions/50329211/qt-open-dialog-from-main-window
-
@AnneRanch
The OP is asking how to design a dialog in Creator/Designer, not how to open one once he has it per your link. That requires him to pick Qt Designer Form as the item to create, not the C++ Class he has been picking so far. We have told him this, and my last post shows him it in pictures. Cannot be clearer or more helpful than that.