Results 1 to 20 of 22

Thread: How to stop multiple appearance of a widget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default How to stop multiple appearance of a widget

    hi all,
    I have an application in which when I press a button I should get a find dialog box. Thing is if I press the button again, I shouldnot get one more dialog box. The previous one should appear.
    My present code is like this:
    Qt Code:
    1. CPT::CPT(QWidget *parent):QWidget(parent)
    2. {
    3. //some other lines of code
    4. QPushButton *but=new QPushButton(this);
    5. QObject::connect(but,SIGNAL(clicked()),this,SLOT(findbox()));
    6. //remaining program
    7. }
    8. void CPT::findbox()
    9. {
    10. QWidget *findstr=new QWidget;
    11. //other widgets added to it
    12. findstr->show();
    13. }
    To copy to clipboard, switch view to plain text mode 
    So kindly help me in this problem.

  2. #2
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to stop multiple appearance of a widget

    Qt Code:
    1. Window::showFindDialog(){
    2. static FindDialog* pFindDlg = 0;
    3. if( pFindDlg == 0 ) {
    4. pFindDlg = new FindDialog( this, "") ;
    5. }
    6. pFindDlg->show();
    7. pFindDlg->raise();
    8. pFindDlg->setActiveWindow();
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 
    We can't solve problems by using the same kind of thinking we used when we created them

  3. #3
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to stop multiple appearance of a widget

    hi sunil,
    can you please show me the changes that I have to make in my program. And u have written FindDialog in your code. Is there any such default dialog box provided by Qt.

    regards,
    Sarma.

  4. #4
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to stop multiple appearance of a widget

    I just called the Dialog you wanted to show as FindDialog That is all !
    We can't solve problems by using the same kind of thinking we used when we created them

  5. #5
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to stop multiple appearance of a widget

    sorry sunil,
    That is giving good number of errors. It says that the second line (of your code) is wrong and because of this, it says that pFindDlg is not defined. can you suggest me other method

  6. #6
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to stop multiple appearance of a widget

    Try the Attachment
    Attached Files Attached Files
    We can't solve problems by using the same kind of thinking we used when we created them

  7. #7
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to stop multiple appearance of a widget

    hi sunil,
    well, thanks for your help. But no where I have found the code that you have written previously. In which file should I see that . And can you please tell me how to generate the .ui files and use them in our ordinary program.

    Thanks & regards,
    Sarma.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to stop multiple appearance of a widget


  9. #9
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to stop multiple appearance of a widget

    sir,
    Iam getting errors as I said previously . Kindly show me the changes that I have to make in my code(I have send it in my first post).

    Thanks & regards,
    Sarma.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to stop multiple appearance of a widget

    Look at the FAQ entry I mentioned. The code is there -- literally. Especially note the "static" keyword.

  11. #11
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How to stop multiple appearance of a widget

    sir,
    I have modified my code like this:
    Qt Code:
    1. CPT::CPT(QWidget *parent):QWidget(parent)
    2. {
    3. //some other lines of code
    4. QPushButton *but=new QPushButton(this);
    5. QObject::connect(but,SIGNAL(clicked()),this,SLOT(findbox()));
    6. //remaining program
    7. }
    8. void CPT::findbox()
    9. {
    10. QWidget *fwin=new QWidget;
    11. //other widgets added to it
    12. //fwin->show();
    13. static fwin *form2 = new fwin(this);
    14. form2->show();
    15. form2->activateWindow(); // or form2->setActiveWindow() in Qt3
    16. form2->raise();
    17. }
    To copy to clipboard, switch view to plain text mode 

    And I got the following errors:

    "cptdebug.cpp", line 1501: Error: fwin, of type int, was previously declared QWidget*.
    "cptdebug.cpp", line 1501: Error: Multiple declaration for fwin.
    "cptdebug.cpp", line 1501: Error: "," expected instead of "*".
    "cptdebug.cpp", line 1502: Error: form2 is not defined.
    "cptdebug.cpp", line 1503: Error: form2 is not defined.
    "cptdebug.cpp", line 1504: Error: form2 is not defined.
    Kindly tell me why? And give me the possible solution.

    Thanks and regards,
    Sarma.
    Last edited by Sarma; 9th March 2006 at 09:22.

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  3. Display multiple Images in a widget
    By jeetu_happy in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2007, 11:24

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.