Qt Tutorials For Beginners 9 - How to Show Another Window From MainWindow in QT

  Рет қаралды 247,424

ProgrammingKnowledge

ProgrammingKnowledge

Күн бұрын

In this QT C++ GUI tutorial I will show you How to open a new window from a button. So you will learn to Open new window when button on main-window is clicked. i.e. using QMainWindow open a new QMainWindow, qt open another window, close window qt
transparent window qt, qt create popup window, qt open dialog from mainwindow, qt multiple windows
★★★Top Online Courses From ProgrammingKnowledge ★★★
Python Programming Course ➡️ bit.ly/2vsuMaS ⚫️ bit.ly/2GOaeQB
Java Programming Course ➡️ bit.ly/2GEfQMf ⚫️ bit.ly/2Vvjy4a
Bash Shell Scripting Course ➡️ bit.ly/2DBVF0C ⚫️ bit.ly/2UM06vF
Linux Command Line Tutorials ➡️ bit.ly/2IXuil0 ⚫️ bit.ly/2IXukt8
C Programming Course ➡️ bit.ly/2GQCiD1 ⚫️ bit.ly/2ZGN6ej
C++ Programming Course ➡️ bit.ly/2V4oEVJ ⚫️ bit.ly/2XMvqMs
PHP Programming Course ➡️ bit.ly/2XP71WH ⚫️ bit.ly/2vs3od6
Android Development Course ➡️ bit.ly/2UHih5H ⚫️ bit.ly/2IMhVci
C# Programming Course ➡️ bit.ly/2Vr7HEl ⚫️ bit.ly/2W6RXTU
JavaFx Programming Course ➡️ bit.ly/2XMvZWA ⚫️ bit.ly/2V2CoAi
NodeJs Programming Course ➡️ bit.ly/2GPg7gA ⚫️ bit.ly/2GQYTQ2
Jenkins Course For Developers and DevOps ➡️ bit.ly/2Wd4l4W ⚫️ bit.ly/2J1B1ug
Scala Programming Tutorial Course ➡️ bit.ly/2PysyA4 ⚫️ bit.ly/2PCaVj2
Bootstrap Responsive Web Design Tutorial ➡️ bit.ly/2DFQ2yC ⚫️ bit.ly/2VoJWwH
MongoDB Tutorial Course ➡️ bit.ly/2LaCJfP ⚫️ bit.ly/2WaI7Ap
QT C++ GUI Tutorial For Beginners ➡️ bit.ly/2vwqHSZ
★★★ Online Courses to learn ★★★
Get 2 FREE Months of Unlimited Classes from skillshare - skillshare.eqc...
Data Science - bit.ly/2lD9h5L | bit.ly/2lI8wIl
Machine Learning - bit.ly/2WGGQpb | bit.ly/2GghLXX
Artificial Intelligence - bit.ly/2lYqaYx | bit.ly/2NmaPya
MERN Stack E-Degree Program - bit.ly/2kx2NFe | bit.ly/2lWj4no
DevOps E-degree - bit.ly/2k1PwUQ | bit.ly/2k8Ypfy
Data Analytics with R - bit.ly/2lBKqz8 | bit.ly/2lAjos3
AWS Certification Training - bit.ly/2kmLtTu | bit.ly/2lAkQL1
Projects in Java - bit.ly/2kzn25d | bit.ly/2lBMffs
Machine Learning With TensorFlow - bit.ly/2m1z3AF | bit.ly/2lBMhnA
Angular 8 - Complete Essential Guide - bit.ly/2lYvYRP
Kotlin Android Development Masterclass - bit.ly/2GcblsI
Learn iOS Programming Building Advance Projects - bit.ly/2kyX7ue
★★★ Follow ★★★
My Website - www.codebind.com
DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!

Пікірлер: 99
@mikkykyluc5804
@mikkykyluc5804 4 жыл бұрын
Thank you very much! I'm a 1-year programming student and wanted to experiment with making a simple GUI-based text game, this is just what I needed :)
@RicardoAGLourenco
@RicardoAGLourenco 8 жыл бұрын
My tip of the day ... Help him seeing the ad to the end
@skyletwings5711
@skyletwings5711 7 жыл бұрын
100% exactly what I was looking for. Thanks a lot!
@user-ww2lc1yo9c
@user-ww2lc1yo9c 9 ай бұрын
As expected, there is a lot of sophistication in creating GUIs, lot of options and widgets to make that easy. I learnt VB6 almost 20 years ago. This seems so much more better than that technology.
@andrexbsb
@andrexbsb 8 жыл бұрын
Very good. In this video you say everything I was looking for and was not finding. Thank you very much.
@MikeSmith-te6cn
@MikeSmith-te6cn Жыл бұрын
Thanks, I'm new to Qt and wasn't given much time for this aspect of the project and the learning curve involved with any software package like Qt. Videos like yours help tremendously. Good work !
@thex-man9153
@thex-man9153 5 жыл бұрын
Hi, please assist me. How can I pass data from the dialog window to the mainwindow? Like to write something on a dialog window and when I press a button it should appear on the main window
@yashgovindani4234
@yashgovindani4234 3 жыл бұрын
You have explained it nicely; but a small request can you also add videos on how create installer for qt applications using Qt Installer Framework (For : Mac, Windows as well as Linux).
@tobyadams5763
@tobyadams5763 Жыл бұрын
I'm out of a fix once more...thanks to this video!😀
@user-ql7pw7ld1n
@user-ql7pw7ld1n 4 ай бұрын
Amazing..loved it fully
@katjaczajkov8694
@katjaczajkov8694 4 жыл бұрын
i prefer to use some different words, so any people can learn it easy like this exam. S2 = new Sec_Dialog(this); S2->exec(); so u see better that Sec_Dialog must be the class and S2 the object. different words, better readable
@MoesKeckeEcke
@MoesKeckeEcke 5 жыл бұрын
Keyboard Shortcut used at 7:57 (Un)Comment Selection Press CTRL + /
@MJ-og8zg
@MJ-og8zg 4 жыл бұрын
mac users: command + /
@BharathRamMS
@BharathRamMS 3 жыл бұрын
Thanks
@eldukasoooficial5601
@eldukasoooficial5601 3 ай бұрын
There you use setmodal because the new window you open is QWidget, and if the new window to open was of type QMainWindow, what should I put instead of setmodal?
@georgymoshkin2079
@georgymoshkin2079 7 жыл бұрын
Excellent tutorials! While learning this one I got an error "expected type specifier". It was problem with capital letter: secDialog=new SecDialog(this); SecDialog=new secDialog(this); Anyone having the same error pay attention to variable names (small letters or capital letters).
@malbarenque
@malbarenque 5 жыл бұрын
Thank you from Argentina
@valizeth4073
@valizeth4073 5 жыл бұрын
Shouldn't you delete the memory for the secDialog* ? I've heard about Qt's reference counting but yet, you call delete ui in the main window destructor?
@TheFinalCutBG
@TheFinalCutBG 4 жыл бұрын
There is WAY BIGGER PROBLEM here. Since the constructor of secDialog takes this as argument, it is a child of QMainWindow, when QMainWindow gets destroyed, it will destroy the dialog also... BUT in the example shown in the video on EVERY click, a new Dialog is created, and the pointer to the previous one is lost inevitably, hence a memory leak occurs. The correct way to do it is to create the dialog in the constructor of QMainWindow and assign the button to only show it. Edit: Even if QT tracks the allocations and deletes them later, it's absolutely pointless to create the same thing over and over again... it's just stupid.
@priyeshgupta164
@priyeshgupta164 2 жыл бұрын
@@TheFinalCutBG please respond if you can find the time for the question:: how to create a single 2nd dialogue from push button in mainn window; and keep on showing the same dialogue if the button is clicked again, without creating more instances of 2nd dialogue window.
@TheFinalCutBG
@TheFinalCutBG 2 жыл бұрын
@@priyeshgupta164 if you want your second dialog to keep a certain state, make it a member variable (not a pointer) of QMainWindow. That way it lives as long as QMainWindow lives, and when QMainWindow is destroyed, the dialog is automatically destroyed also. The parent argument in the constructor of the second dialog should be nullptr. When the button is clicked, you call second dialog's show() function.
@chanyanhan7791
@chanyanhan7791 2 жыл бұрын
Thanks for that :") It help me a lot and what if I used back button how do I go back ?
@sachinacharya1032
@sachinacharya1032 5 жыл бұрын
I'm developing a Qt application for the nanopc t2. I have a few different screens and as I move forward and back through the different screens, the application gets slower and slower. In the end it gets very slow.
@just_kidding_kid
@just_kidding_kid 4 жыл бұрын
That was helpful, thanks for video
@niltonrodolforodrigues9093
@niltonrodolforodrigues9093 2 жыл бұрын
Thanks!
@masintec
@masintec 5 жыл бұрын
thanks for your sharing !
@Manas-co8wl
@Manas-co8wl 3 жыл бұрын
I checked the docs and exec() always pops the dialog as modal, ignoring the parameter set by setModal method
@duzantj-laurent7784
@duzantj-laurent7784 7 жыл бұрын
how can i pass data/variables from my mainwindow to an other window (dialog) ? is that possible ? if so you do a tutorial pls
@paulg.3067
@paulg.3067 4 жыл бұрын
isn’t signals&slots meant to be used for that ?
@iordanbaltaliiski2882
@iordanbaltaliiski2882 3 жыл бұрын
Great video :)
@digimikeh
@digimikeh 4 жыл бұрын
Perfect
@user-bc8pr5up2r
@user-bc8pr5up2r 7 жыл бұрын
very well!
@maurofoti526
@maurofoti526 7 жыл бұрын
you forgot to call the delete on secDialog in the destructor
@Xerox482
@Xerox482 5 жыл бұрын
it will generate xxxx.exe have stopped working popup in case you have not opened child windows and directly close the main window.
@cooldued00755
@cooldued00755 8 жыл бұрын
how to make the mainwindow show up again once we close the second dialog,
@rusikarhireev
@rusikarhireev 7 жыл бұрын
In secdialog.ui right click on the main window and "Go to slot" -> "finished(int)". In generated function you just have to call "show" function on the object returned by parentWidget(): void SecondDialog::on_SecDialog_finished(int result) { parentWidget()->show(); }
@xuelin9983
@xuelin9983 6 жыл бұрын
in SecondDialog::SecondDialog, add this code ===> connect(this, SIGNAL(finished(int)), this->parentWidget(), SLOT(show()));
@altankursad
@altankursad 6 жыл бұрын
QObject::connect: No such signal programHazirla::finished(int) in ../YayMakinesi2Eksen/programhazirla.cpp:9 QObject::connect: (sender name: 'programHazirla') QObject::connect: (receiver name: 'MainWindow') programHazirla is my second window... When I click button on second window is hidden but main window is not show again.. How Can i solve that problem?
@altankursad
@altankursad 6 жыл бұрын
I solved i think. On button click in second window, i add this->parentWidget()->show(); functions. after hide() command.
@zakariachahboun
@zakariachahboun 7 жыл бұрын
thank you :)
@rosariodipalma8564
@rosariodipalma8564 7 жыл бұрын
Nice tutorial. But the secDialog object when it is deallocated?
@musabse
@musabse 8 жыл бұрын
nice
@WHWrooolz
@WHWrooolz 3 жыл бұрын
I don't want to open up a sepparate dialogue window. what I want to do is open up a new view over the main window. I want the user to navigate with pushbuttons to different pages within the mainWindow, without a sepparate modal/non-modal dialogue. So lets say I'm making an educational tool, and my main window shows a title screen along with buttons to navigate from one layout to another, and I want one of those buttons to open up a display with text. I don't want that to generate in a separate window. how would I approach this?
@RodCDavid
@RodCDavid 2 жыл бұрын
Don't know if you have found this yet, but you can use the stacked widget.
@pinniramakrishna2467
@pinniramakrishna2467 6 жыл бұрын
I need to work on multiple windows plz help me. Example I have 3 windows win1, win2 and win3. Win1 has a button that can open win2, win2 has a button that can open win3, win3 has two buttons one is to open win2 another for win1. My problem is how to open(show) win1 from win3. Sorry for any grammatical mistakes.
@user-ww2lc1yo9c
@user-ww2lc1yo9c 9 ай бұрын
When you wrote secDialog = new SecDialog(this); Is it supposed to create a new secDialog window everytime you click it?
@pheebsbuffayy
@pheebsbuffayy Ай бұрын
Do you know the answer now
@geordirendum583
@geordirendum583 2 жыл бұрын
is it me or you have to add :delete secdialog in the destructor of the main window since we allocated a pointer with ''new''?
@lopo8000
@lopo8000 2 жыл бұрын
how do i show a picture opening a new window like in this video
@navarajpokharel8980
@navarajpokharel8980 7 жыл бұрын
I got but how to get back to previous window plz help me in my project 💌
@Nathaniel-jr3hn
@Nathaniel-jr3hn 7 ай бұрын
How do I hide the other form
@mellahhamida6914
@mellahhamida6914 7 жыл бұрын
Hy, i have a problem when i choose add new i don't find "Qt Designer Form Class" i just have "Qt Designer Form" even when I uploaded the same version that you got in the video, Thank u.
@vigopoli
@vigopoli 6 жыл бұрын
Good Morning. I was doing a graphical interface with a lateral menu that according to press one or the other a different ui. The program opens my windows perfectly. And every window the first time I enter works correctly, however the second time I enter, nothing works anymore. I have the suspicion that it is because an object is created ui every time I enter the window. There is some possible solution for this. A greeting and Thanks forward
@awernek81
@awernek81 6 жыл бұрын
I have two windows. The main one is a Dialog. Both work at the same time. When I go to shut down the system, the Dialog screen does not close.
@LOCO.AMP00
@LOCO.AMP00 3 жыл бұрын
how do i connect the window to the menu strip ?
@lopo8000
@lopo8000 2 жыл бұрын
how do i stop sound once secondary window is closed??
@BAT_24
@BAT_24 6 жыл бұрын
sir, can we merge 2 project in a single project???
@gtacarlito
@gtacarlito 4 жыл бұрын
How do i access the widgets of Secdialog, for my mainWindow i am able to access them easily by ui->lineedit->append(); , but how do i access the widgets there on secdialog ???
@oussamasethoum2755
@oussamasethoum2755 4 жыл бұрын
how can i do to update the ui of the main window ?
@satadrubera7281
@satadrubera7281 5 жыл бұрын
I am trying to plot in new window. But I am getting two different windows 1: plot window , 2: blank dialog window. How to overcome this ?
@govindsajgane2301
@govindsajgane2301 5 жыл бұрын
How can we show dialogs based on timings
@roboticsworkshop
@roboticsworkshop 2 жыл бұрын
BUG: but in your program for heap memory actually there is a memory leak because u r using "new" keyword and not deleting it anywhere
@Phatnaru0002
@Phatnaru0002 6 жыл бұрын
ATTENTION: To anyone experiencing the error that says that your class has no member named setModal or exec - It's because of the template you chose when creating your class/header/ui - I'm still a noobie myself, so I don't understand WHY this is causing it, but I can tell you that it IS causing it.
@ShayAxelod22
@ShayAxelod22 5 жыл бұрын
Any idea how to fix it?
@SrQuesoH
@SrQuesoH 2 жыл бұрын
@@ShayAxelod22 they dont have a solution, the error is because only the dialog templates can be called like this. The Main Windows needs to be call with another function. (im sorry if my english is a bit bad x,D)
@HKGamingPak
@HKGamingPak 5 жыл бұрын
How i can open first window from second using button?
@devreddy2010
@devreddy2010 7 жыл бұрын
I did exactly what he said and When i run the code it was poping out a window written hello world on it and when i click on it was closing did anyone had same issue please help where did this hello world came from in window
@mritunjaysingh6684
@mritunjaysingh6684 3 жыл бұрын
how do I make the first window unresponsive while opening the second window?
@ercody_t
@ercody_t 3 жыл бұрын
this->hide()
@dlugi196d
@dlugi196d 6 жыл бұрын
And hide method dosn't hide but close first window, yes or not?
@vizionthing
@vizionthing 5 жыл бұрын
not.
@ryannguyen2170
@ryannguyen2170 5 жыл бұрын
Is there a way to do it without the code?
@vizionthing
@vizionthing 5 жыл бұрын
You need to overcome your programmerphobia
@kishorechandaralapati4991
@kishorechandaralapati4991 6 жыл бұрын
what is the use of .hpp files
@arteqppp6223
@arteqppp6223 6 жыл бұрын
.h - C | .hpp - C++ (both are working for C++)
@dontlike1000
@dontlike1000 7 жыл бұрын
I don't understand why we create second window on a button click. I think it is more obvious to create a pointer to second window right after we create main window. By clicking the button each time we create a new instance of second window in heap. We can create a window one time and then just close and reopen it.
@contificate
@contificate 7 жыл бұрын
In your second dialog's constructor, setAttribute(Qt::WA_DeleteOnClose); This will tell Qt's MOC to delete it for you despite being on the heap. You never have to call delete on it. Qt's MOC can be quite.. devious. So a lot of Qt code that looks like it produces leaks won't.
@artteaparty
@artteaparty 8 жыл бұрын
When I code the void MainWindow::on_pushButton_clicked() { SecondDialog secDi; secDi.setModal(true); secDi.exec(); } and build the program, I get no errors but the run button is not green and available :/ Why can't I run it?
@ninanikdodo
@ninanikdodo 6 жыл бұрын
I am the same!
@arshsaluja8237
@arshsaluja8237 4 жыл бұрын
Did u got the why?
@dlugi196d
@dlugi196d 6 жыл бұрын
Hi, but this method: secDialog = new SecDialog(this); secDialog->show(); dose not blocking to open second window again and again, we can open more then one this second window like duplicate. Any advice?
@MaKetBLUE
@MaKetBLUE 6 жыл бұрын
my advice would be to add "secDialog = nullptr;" in the MainWindow constructor, and only allow creating new window when secDialog = nullptr (using an if statement).
@fab0527
@fab0527 4 жыл бұрын
This is useless. I don't want a new dialog, I want a new mainwindow since I need a menu bar
@user-mc6sm1ut3t
@user-mc6sm1ut3t 7 ай бұрын
.setModal() and .exec() are giving me errors- ‘class SecDialogue’ has no member named 'setModal' and ‘exec’ 22 | secD.exec(); | ^~~~
Qt Tutorials For Beginners 10 -  Simple Login app using QT
14:02
ProgrammingKnowledge
Рет қаралды 158 М.
Delphi App Development #40: A Wild Bug has Appeared!
42:39
The FASTEST way to PASS SNACKS! #shorts #mingweirocks
00:36
mingweirocks
Рет қаралды 14 МЛН
Apple peeling hack
00:37
_vector_
Рет қаралды 82 МЛН
Секрет фокусника! #shorts
00:15
Роман Magic
Рет қаралды 72 МЛН
How To Open A Second Window - PyQt5 GUI Thursdays #24
13:41
Codemy.com
Рет қаралды 66 М.
Qt Tutorials For Beginners - How to Show Another Window From MainWindow in QT
13:01
Hello C & CPP By ProgrammingKnowledge
Рет қаралды 5 М.
Qt Tutorials For Beginners 8 - Spacers, Splitter, Buddy and Tabs
8:54
ProgrammingKnowledge
Рет қаралды 129 М.
Cross Platform Graphical User Interfaces in C++
44:49
javidx9
Рет қаралды 866 М.
Let's Recreate the Tesla UI in Qt and QML PART 1!
51:16
MontyTheSoftwareEngineer
Рет қаралды 70 М.
Qt Tutorials For Beginners 6 - QMessageBox
13:02
ProgrammingKnowledge
Рет қаралды 148 М.
Qt3D CPP Tutorial 1. Шаблон проекта / Project template
30:50
Dmitrii Tikhonkikh
Рет қаралды 5 М.
Qt Tutorials For Beginners 11 - Displaying image using label in Qt
10:26
ProgrammingKnowledge
Рет қаралды 175 М.
The FASTEST way to PASS SNACKS! #shorts #mingweirocks
00:36
mingweirocks
Рет қаралды 14 МЛН