Page 1 of 2 12 LastLast
Results 1 to 20 of 34

Thread: Parent and Child Window Communication

  1. #1
    Join Date
    Nov 2013
    Location
    Hyderabad
    Posts
    52
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Parent and Child Window Communication

    As i'm trying to create a connection b/w parent and child window facing a problem with the following errors & warnings


    /home/stesalit/Desktop/tasks/multi-windw-back/info.cpp:8: error: invalid use of incomplete type ‘struct Ui::Info’
    /home/stesalit/Desktop/tasks/multi-windw-back/info.h:7: error: forward declaration of ‘struct Ui::Info’

    /home/stesalit/Desktop/tasks/multi-windw-back/info.cpp:14: warning: possible problem detected in invocation of delete operator:


    Here are my .h and .cpp files in attachments.Can any one please help me in sorting out the issue????
    Attached Images Attached Images
    • File Type: jpg 2.jpg (61.3 KB, 12 views)
    • File Type: jpg 1.jpg (58.6 KB, 7 views)
    • File Type: jpg 3.jpg (62.0 KB, 6 views)
    • File Type: jpg 4.jpg (51.2 KB, 6 views)
    • File Type: jpg 5.jpg (57.5 KB, 5 views)

  2. The following user says thank you to Harini for this useful post:


  3. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Parent and Child Window Communication

    Ui::Info should have been define in ui_info.h

    This is a generated file, its source file should be info.ui
    Check that the form declared in it is called Info.

    Btw, posting screenshots of code is suboptimal. either attach the project as a ZIP or post the code in code tags

    Oh and it helps if a thread's subject is actually about the problem :-)

    Cheers,
    _

  4. The following user says thank you to anda_skoa for this useful post:


  5. #3
    Join Date
    Nov 2013
    Location
    Hyderabad
    Posts
    52
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Parent and Child Window Communication

    Thanks a lot for ur suggestion AS I'm new to Qt,I dont know how to define Ui::Info in ui_info.h can u please explain me...

  6. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Parent and Child Window Communication

    I assume you have created the files using "New File" and selected "Designer Form Class".
    That will usually generate the files and proper names.

    My guess is that you have a Form file called info.ui but that you have changed the name of the top level item in it.
    If so you can either change it back to "Info" or change the usage of "Info" in info.h and info.cpp to whatever name you have now chosen.

    Cheers,
    _

  7. #5
    Join Date
    Nov 2013
    Location
    Hyderabad
    Posts
    52
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Parent and Child Window Communication

    Thank you sir @ anda_skoa

    But here I'm getting only parent window am not getting any child.There is no communication b/w parent and child. Here is my code can please suggest me anything

    Qt Code:
    1. #ifndef INFO_H
    2. #define INFO_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class info;
    8. }
    9.  
    10. class info : public QMainWindow {
    11. Q_OBJECT
    12. public:
    13. info(QWidget *parent = 0);
    14. ~info();
    15.  
    16. protected:
    17. void changeEvent(QEvent *e);
    18.  
    19. private:
    20. Ui::info *ui;
    21. };
    22.  
    23.  
    24. #endif // INFO_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <info.h>
    6. #include <QtGui>
    7.  
    8. namespace Ui {
    9. class MainWindow;
    10. }
    11.  
    12. class MainWindow : public QMainWindow {
    13. Q_OBJECT
    14. public:
    15. MainWindow(QWidget *parent = 0);
    16. ~MainWindow();
    17.  
    18. protected:
    19. void changeEvent(QEvent *e);
    20.  
    21. private:
    22. Ui::MainWindow *ui;
    23. void setSignals();
    24. void process();
    25. };
    26.  
    27. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "info.h"
    3. #include "ui_info.h"
    4.  
    5. info::info(QWidget *parent) :
    6. QMainWindow(parent)
    7. //ui(new Ui::info)
    8. {
    9. ui->setupUi(this);
    10. }
    11.  
    12. info::~info()
    13. {
    14. delete ui;
    15. }
    16.  
    17. void info::changeEvent(QEvent *e)
    18. {
    19. QMainWindow::changeEvent(e);
    20. switch (e->type()) {
    21. case QEvent::LanguageChange:
    22. ui->retranslateUi(this);
    23. break;
    24. default:
    25. break;
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3. #include "info.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8. MainWindow w;
    9. w.show();
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. setSignals();
    10. }
    11.  
    12. MainWindow::~MainWindow()
    13. {
    14. delete ui;
    15. }
    16.  
    17. void MainWindow::changeEvent(QEvent *e)
    18. {
    19. QMainWindow::changeEvent(e);
    20. switch (e->type()) {
    21. case QEvent::LanguageChange:
    22. ui->retranslateUi(this);
    23. break;
    24. default:
    25. break;
    26. }
    27. }
    28. void MainWindow::setSignals(){
    29. connect(ui->next,SIGNAL(clicked()),this,SLOT(process()));
    30. //connect(ui->close,SIGNAL(clicked()),this,SLOT(close()));
    31. }
    32.  
    33. void MainWindow::process(){
    34. info *i;
    35. i = new info;
    36. this -> hide();
    37. i -> show();
    38. }
    To copy to clipboard, switch view to plain text mode 

  8. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Parent and Child Window Communication

    This probably not compiling (missing include of info.h in the main window source file, and probably crashing because info's source file does not create an instance of the UI class (commented out) but accesses it.

    However, MainWindow:rocess() looks right though.

    Do you get any runtime warning?

    Cheers,
    _

  9. #7
    Join Date
    Nov 2013
    Location
    Hyderabad
    Posts
    52
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Parent and Child Window Communication

    @ anda_skoa

    Thanks a lot for ur reply


    I dint get any error or warning and now I included info.h in main window source file but still facing the same problem.

  10. #8
    Join Date
    Nov 2013
    Location
    Hyderabad
    Posts
    52
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question How to add custom slot in signal slot editor

    Hii every one

    I want to create a parent and child window. From the parent window i want to call the child window by using signal and slots so here in the ui form i want to customize the slot editor with process().
    Here is my signal and slot connection code line which I want to do...

    Qt Code:
    1. connect(ui->next,SIGNAL(clicked()),this,SLOT(process()));
    To copy to clipboard, switch view to plain text mode 

    How can i do this?? can any one please help me???
    Last edited by Harini; 23rd November 2013 at 08:03.

  11. #9
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to add custom slot in signal slot editor

    You add your intended slot in the header file where the slot will be invoked under public sots.
    Qt Code:
    1. class nameQueryThread ...
    2. {
    3.  
    4. public:
    5. nameQueryThread(...);
    6. ...
    7. signals:
    8.  
    9. public slots:
    10. void process();
    11. };
    To copy to clipboard, switch view to plain text mode 

    From the parent window i want to call the child window by using signal and slots
    What do you mean ?
    In your slot process create and call the * child window *
    in your cpp file
    Qt Code:
    1. void window::process()
    2. {
    3. // do your code here
    4. // create and call your child window
    5. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by toufic.dbouk; 23rd November 2013 at 12:26. Reason: Typo

  12. The following user says thank you to toufic.dbouk for this useful post:

    Harini (25th November 2013)

  13. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Parent and Child Window Communication

    Can you attach the project as ZIP file?

    Cheers,
    _

  14. #11
    Join Date
    Nov 2013
    Location
    Hyderabad
    Posts
    52
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Parent and Child Window Communication

    @ anda_skoa


    yea sure here is my zip file in attachments please solve it
    Attached Files Attached Files

  15. #12
    Join Date
    Nov 2013
    Location
    Hyderabad
    Posts
    52
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to add custom slot in signal slot editor

    @ toufic.dbouk

    Thank you


    Here is my project in zip file can u please check it out and suggest me something if i have done any mistake???
    Attached Files Attached Files

  16. #13
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How to add custom slot in signal slot editor

    You have defined process() as a private member in your MainWindow class again. instead define it as a public slots as below:
    Qt Code:
    1. class MainWindow : public QMainWindow {
    2. Q_OBJECT
    3. public:
    4. MainWindow(QWidget *parent = 0);
    5. ~MainWindow();
    6.  
    7. protected:
    8. void changeEvent(QEvent *e);
    9.  
    10. public slots:
    11. void process();
    12. private:
    13. Ui::MainWindow *ui;
    14. void setSignals();
    15. };
    To copy to clipboard, switch view to plain text mode 

  17. #14
    Join Date
    Nov 2013
    Location
    Hyderabad
    Posts
    52
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to add custom slot in signal slot editor

    @ saman_artorious


    Thank you for u'r suggestion


    I did as u suggested but still I'm not getting the process slot in the signal and slot area of the form.please help me.....

  18. #15
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How to add custom slot in signal slot editor

    Quote Originally Posted by Harini View Post
    @ saman_artorious


    Thank you for u'r suggestion


    I did as u suggested but still I'm not getting the process slot in the signal and slot area of the form.please help me.....

    I am checking your code, it is possible to do that:
    Qt Code:
    1. void MainWindow::setSignals(){
    2. connect(ui->next,SIGNAL(clicked()),this,SLOT(process()));
    To copy to clipboard, switch view to plain text mode 

    so what is the problem!? you have access to your SLOT inside connect. (don't forget to include QObject)

  19. #16
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to add custom slot in signal slot editor

    Your code is okay.
    your application crashes upon clicking the next button because you are creating an info object and showing it but in your info.cpp you dont initailse the UI.
    Qt Code:
    1. info::info(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::info)
    4. {
    5. ui->setupUi(this);
    6. }
    To copy to clipboard, switch view to plain text mode 
    .

    The slot process() gets executed upon clicking next so your connect statement works.
    Now do whatever you want in that slot.
    Something like:
    Qt Code:
    1. void MainWindow::process()
    2. {
    3. // this->hide(); /*if you wanna use the hide function you have to take care of info's parent.*/
    4. info *i = new info(this);
    5. i->show();
    6. }
    To copy to clipboard, switch view to plain text mode 


    Good Luck.

  20. #17
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Parent and Child Window Communication

    MainWindow:rocess() is a slot, but it is not declared in a slots section

    Qt Code:
    1. private slots:
    2. void process();
    To copy to clipboard, switch view to plain text mode 

    Which of course the application tells you when you start it.

    In programming it is generally a good idea to fix errors that are reported by the build and the program.

    Cheers,
    _

  21. #18
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to add custom slot in signal slot editor

    Oh great, I just wasted time on a double poster.

    Merging thread as an educational example and making sure the perpertators is recognized as such.

  22. #19
    Join Date
    Nov 2013
    Location
    Hyderabad
    Posts
    52
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to add custom slot in signal slot editor

    @ anda_skoa

    Sorry sir ,I dint get u

  23. #20
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to add custom slot in signal slot editor

    My previous post shows how to solve the problem. And as mentioned above by anda_skoa your slot process() is declared in the header file not as a Slot. You should declare it under the public or private slots.


    Good Luck.

Similar Threads

  1. Replies: 5
    Last Post: 17th September 2013, 06:45
  2. resizing child window with parent window
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 3
    Last Post: 8th May 2012, 19:02
  3. Parent Child for window
    By febil in forum Qt Programming
    Replies: 6
    Last Post: 1st April 2009, 05:00
  4. How to close parent window from child window?
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2008, 11:40
  5. Replies: 11
    Last Post: 4th June 2008, 07:22

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.