Results 1 to 11 of 11

Thread: update form

  1. #1
    Join Date
    Jun 2011
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default update form

    hi everyone how to update form without member show? Because i ever call member show it show another form

  2. #2
    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: update form

    My guess is you are creating a new object instead of reusing the original one.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2011
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: update form

    i have form1 and form2. when i click button of form1 form2 shown and then i click ok on form2 i create an object of form1 and calling member show.

  4. #4
    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: update form

    So why are you suprised another form pops up when you show it?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2011
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: update form

    thanks for reply . i said before i want to to update form without method show. in form 1 i have tablewidget and label when i show form2 the user enter id when the user click on okbutton in form2 i want in form1 show the information of user but i can'nt see the information until i calling member show.can you give me a way for update form1.

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: update form

    Quote Originally Posted by hamidarr
    i have form1 and form2. when i click button of form1 form2 shown and then i click ok on form2 i create an object of form1 and calling member show.
    You should not be creating object of form1 when you click on form 2.

    Try to reliaze this sequence,

    1. Create Form1 object, let say From1Obj1
    2. show From1Obj1
    3. user clicks on From1Obj
    4. create Form2 object, let say From2Obj1
    5. user clicks on From2Obj1
    6. show From1Obj1 (simple repeat sept 2 only. Don't do setp 1, if you do step 1, you will end up having From1Obj2 and which is different from From1Obj1)
    7. Now how does form2 send information (user enter id) to form1 ?

  7. #7
    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: update form

    form2 should be a dialog executed using QDialog::exec() from within form1. After the dialog is closed, you can query its results and update form1.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Jun 2011
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: update form

    sorry for late
    here is my code:
    student.h


    Qt Code:
    1. #ifndef STUDENT_H
    2. #define STUDENT_H
    3. #include <QWidget>
    4. #include "ui_student.h"
    5. class Student : public QWidget , public Ui::Student
    6. {
    7. Q_OBJECT
    8.  
    9. public:
    10. Student(QWidget *parent = 0);
    11. ~Student();
    12. bool opendb();
    13. void view(int sh_d);
    14. };
    15.  
    16. #endif
    To copy to clipboard, switch view to plain text mode 

    studend.cpp

    Qt Code:
    1. #include "student.h"
    2. #include "ui_student.h"
    3. #include <QSqlRecord>
    4. #include <QSqlError>
    5. extern int id;
    6.  
    7.  
    8. Student::Student(QWidget *parent) :
    9. QWidget(parent)
    10.  
    11. {
    12.  
    13. setupUi(this);
    14. createaction();
    15. }
    16.  
    17. Student::~Student()
    18. {
    19.  
    20. }
    21.  
    22.  
    23. void Student::createaction()
    24. {
    25. connect(Sbutton,SIGNAL(clicked()),this,SLOT(searchstudent())) ;
    26.  
    27.  
    28. }
    29.  
    30. void Student::searchstudent()
    31. {
    32.  
    33. StudentSearch *s = new StudentSearch;
    34. s->show();
    35.  
    36. }
    37.  
    38. void Student::viewinfo(int sh_d)
    39. {
    40.  
    41.  
    42.  
    43.  
    44. {
    45.  
    46.  
    47. if(opendb())
    48. {
    49.  
    50.  
    51. QSqlQuery query(QSqlDatabase::database("con"));
    52. query.setForwardOnly(true);
    53. query.exec(QString("{CALL information(%1)}").arg(sh_d));
    54. if(!query.isActive())
    55. {
    56.  
    57. QMessageBox::warning(this, tr("Error"),
    58. query.lastError().text()+"Please Contact to Programer");
    59.  
    60.  
    61. }
    62. else
    63. {
    64.  
    65. while(query.next())
    66. {
    67.  
    68. rec = query.record();
    69.  
    70. N_label->setText(rec.value(0).toString());
    71. F_label->setText(rec.value(1).toString());
    72. C_label->setText(rec.value(2).toString());
    73. M_label->setText(rec.value(3).toString());
    74. D_label->setText(rec.value(4).toString());
    75. SH_label->setText(rec.value(5).toString());
    76.  
    77.  
    78. }
    79. else
    80. {
    81. QMessageBox::critical(0, QObject::tr("Database Error"),
    82. "can'nt open database");
    83. }
    84.  
    85.  
    86.  
    87. }
    88.  
    89.  
    90.  
    91. }
    92.  
    93.  
    94.  
    95.  
    96.  
    97. }
    98.  
    99.  
    100.  
    101. }
    102.  
    103. bool Student::opendb()
    104. {
    105. QSqlDatabase db = QSqlDatabase::addDatabase("QODBC","con");
    106. db.setHostName("pishtazanedu.ir");
    107.  
    108. db.setDatabaseName("pop;DBQ=University.mdf");
    109. db.setUserName("hamidarrb");
    110. db.setPassword("ham!dArr_12973864");
    111.  
    112. if(!db.open())
    113.  
    114. return false;
    115.  
    116.  
    117.  
    118. return true;
    119. }
    To copy to clipboard, switch view to plain text mode 



    StudentSearch.h

    Qt Code:
    1. #ifndef STUDENTSEARCH_H
    2. #define STUDENTSEARCH_H
    3.  
    4. #include <QWidget>
    5. #include <QtGui>
    6. #include "student.h"
    7.  
    8. #include "ui_studentsearch.h"
    9.  
    10.  
    11. class StudentSearch : public QWidget , public Ui::StudentSearch
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. StudentSearch(QWidget *parent = 0);
    17. ~StudentSearch();
    18. void createaction();
    19. private slots:
    20. void search();
    21.  
    22.  
    23. };
    24.  
    25. #endif
    To copy to clipboard, switch view to plain text mode 



    studentsearch.cpp
    Qt Code:
    1. #include "studentsearch.h"
    2. #include "student.h"
    3.  
    4. extern int id;
    5. StudentSearch::StudentSearch(QWidget *parent)
    6. :QWidget(parent)
    7.  
    8. {
    9.  
    10. setupUi(this);
    11. createaction();
    12.  
    13.  
    14. }
    15. StudentSearch::~StudentSearch()
    16. {
    17.  
    18. }
    19.  
    20. void StudentSearch::createaction()
    21. {
    22. connect(okbutton,SIGNAL(clicked()),this,SLOT(search()));
    23. connect(cancelbutton,SIGNAL(clicked()),this,SLOT(close());
    24. }
    25.  
    26. void StudentSearch::searchstudent()
    27. {
    28. id = addlineEdit->text().toInt();
    29. Student *s = new Student;//my problem is here
    30. s->viewinfo(id) //i call member viewinfo but student form do'nt show anything
    31. // if i here i call s->show; it show anothe form and i can see
    32. //the information of student
    33. StudentSearch::close();
    34.  
    35.  
    36. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by hamidarr; 25th June 2011 at 14:57.

  9. #9
    Join Date
    Jun 2011
    Location
    Finland
    Posts
    164
    Thanks
    1
    Thanked 26 Times in 26 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: update form

    Shouldn't you hide your passwords at least?

    Okay, this is not a real solution, neither a good one, but it should work and is definitely fastest way to make your code work.

    Qt Code:
    1. void Student::searchstudent()
    2. {
    3.  
    4. StudentSearch *s = new StudentSearch();
    5. if(id = s->exec())
    6. viewinfo(id);
    7. }
    To copy to clipboard, switch view to plain text mode 

    In your student search class:

    Qt Code:
    1. void StudentSearch::searchstudent()
    2. {
    3. id = addlineEdit->text().toInt();
    4. setResult(id);
    5. StudentSearch::close();
    6. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Rachol; 25th June 2011 at 15:45.

  10. #10
    Join Date
    Jun 2011
    Posts
    21
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: update form

    Thanks.it's work.

  11. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: update form

    Qt Code:
    1. void Student::searchstudent()
    2. {
    3.  
    4. StudentSearch *s = new StudentSearch;
    5. s->show();
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 
    OK. Here you open a new StudentSearch widget in the same fashion you would open a modeless dialog. You do this if you want the search window to stay open and allow user interaction with the student record window.
    Qt Code:
    1. void StudentSearch::searchstudent()
    2. {
    3. id = addlineEdit->text().toInt();
    4. Student *s = new Student;//my problem is here
    5. s->viewinfo(id) //i call member viewinfo but student form do'nt show anything
    6. // if i here i call s->show; it show anothe form and i can see
    7. //the information of student
    8. StudentSearch::close();
    9. }
    To copy to clipboard, switch view to plain text mode 
    At line 4 you create a new instance of the Student window and prepare it to show a particular student [5]. This new instance does not have any visible effect until/unless you call show() when a new window is shown. This is not surprising but also clearly not what you wanted to happen.

    You have two options:
    • Open the StudentSearch widget as a modal dialog. When the user clicks OK you use a public method of the StudentSearch class to access the selected value, and then display the student. This all happens in Student::searchstudent(). Wysota suggested this earlier.
    • Open the StudentSearch as a modeless dialog. When the user selects a student you emit a signal (carrying the student number) that is connected to a slot you need to write in the Student class. This slot should display the student record passed in.

    Which you choose is up to you. StudentSearch should probably be a QDialog derivative in either case.

Similar Threads

  1. How to get previous form from current form
    By keyurparekh in forum Newbie
    Replies: 5
    Last Post: 9th August 2011, 12:31
  2. How to hide from taskbar a form showed form mainwindow
    By tonnot in forum Qt Programming
    Replies: 1
    Last Post: 10th February 2011, 14:36
  3. Pass variable from a form to another form
    By dark1988 in forum Qt Programming
    Replies: 5
    Last Post: 8th February 2011, 18:19
  4. Replies: 2
    Last Post: 29th September 2010, 17:44
  5. Calling a new form from current form
    By webgenius in forum Qt Programming
    Replies: 7
    Last Post: 8th April 2007, 19:50

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.