Results 1 to 13 of 13

Thread: ui problem

  1. #1
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default ui problem

    I have two classes that share the same ui.One is the main class called classM and other a sub class of classM called classS.

    I am able to effect he ui in classM and get data from the ui(i have a line edit and a few more such input widgets)

    But when i try to change the ui from the sublcass classS, it does nothing. It doesnt show any errors eother, but always gives back a blank string for text command in line edit.

    This is the header of classM
    Qt Code:
    1. namespace Ui
    2. {
    3. class classMui;
    4. }
    5. class classM : public QMainWindow
    6. {
    7. Q_OBJECT
    8. private:
    9. Ui::classMui *ui;
    To copy to clipboard, switch view to plain text mode 

    This is the header of classS

    Qt Code:
    1. namespace Ui
    2. {
    3. class classMui;
    4. }
    5. class classS : public QMainWindow
    6. {
    7. Q_OBJECT
    8.  
    9. private:
    10. Ui::classMui *ui;
    To copy to clipboard, switch view to plain text mode 

    ui->passEdit->text();;

    I am able to get text for this same code in classM, where as in classS, it gives me a emty string.

    what am i doing wrong?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ui problem

    you creates two different objects of Ui::classMui in a memory. don't mix up classes and objects.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: ui problem

    ok. So i shouldn't declare classMui in classS??

    then how will ui->.... will know which ui to contact?

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ui problem

    Quote Originally Posted by srohit24 View Post
    ok. So i shouldn't declare classMui in classS??
    I did not say that.

    if I understand you correct, you need to change ui in one object and get exactly the same changes in another object, right?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: ui problem

    yup. both the objects should affect the same ui and also should be able to get data from the same ui

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ui problem

    it should not work in that way which you posted (I already said that in my first post), because in this case your forms should have one instance of classMui, but it is bad idea, because when you will call classMui::setupUi for second object that can lead to unexpected behavior.

    it's better to use signal/slot mechanism for syncronization your forms.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: ui problem

    I have a progress bar in the ui.
    It will be first set at 10% in the classM, then the execution is handed over to classS where the progress bar moves to 90.

    After this it has to get back to classM to complete the execution.

    How can set values to the progress bar using the signals??

  8. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ui problem

    make a signal valueChanged in classM then connect that signal with QProgressBar::setValue of classS.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. #9
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: ui problem

    I removed all the ui related code and removed the instance of the ui class in classS but still I am still not able to see the progress bar or the status bar in classM.

  10. #10
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: ui problem

    I tried it out. here is my files

    mainwindow.h

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

    mainwindow.cpp

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include "class2.h"
    4.  
    5. MainWindow::MainWindow(QWidget *parent)
    6. : QMainWindow(parent), ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. ui->progressBar->setRange(0,100);
    10.  
    11. class2 *class2_object = new class2;
    12.  
    13. connect(class2_object,SIGNAL(change_progress_bar()), this, SLOT(set_progress_bar()));
    14.  
    15. }
    16.  
    17. void MainWindow::set_progress_bar()
    18. {
    19. ui->progressBar->setValue(20);
    20. }
    21.  
    22. MainWindow::~MainWindow()
    23. {
    24. delete ui;
    25. }
    To copy to clipboard, switch view to plain text mode 

    class2.h

    Qt Code:
    1. #ifndef CLASS2_H
    2. #define CLASS2_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. class class2 : public QMainWindow
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. class2();
    12. void dummy();
    13.  
    14. signals:
    15. void change_progress_bar();
    16. };
    17.  
    18. #endif // CLASS2_H
    To copy to clipboard, switch view to plain text mode 

    class2.cpp

    Qt Code:
    1. #include "class2.h"
    2. #include "mainwindow.h"
    3. #include <QDebug>
    4.  
    5. class2::class2()
    6. {
    7. dummy();
    8. }
    9.  
    10. void class2::dummy()
    11. {
    12. qDebug() << "Before signal is sent";
    13. emit (change_progress_bar());
    14. qDebug() << "After signal is sent";
    15. }
    To copy to clipboard, switch view to plain text mode 

    This the output i am getting

    Qt Code:
    1. Before signal is sent
    2. After signal is sent
    To copy to clipboard, switch view to plain text mode 

    but the progress bar in the ui, isnt at 20%

    what should i change??

  11. #11
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ui problem

    add qDebug here
    Qt Code:
    1. void MainWindow::set_progress_bar()
    2. {
    3. ui->progressBar->setValue(20);
    4. qDebuig() << "executed";
    5. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  12. #12
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: ui problem

    btw, you send a signal before connection
    Qt Code:
    1. class2 *class2_object = new class2;//right here you create an object and send a signal
    2. //but the connection is not established yet.
    3.  
    4. connect(class2_object,SIGNAL(change_progress_bar()), this, SLOT(set_progress_bar()));//establishing connection
    To copy to clipboard, switch view to plain text mode 
    try to do this
    Qt Code:
    1. class2 *class2_object = new class2;
    2.  
    3. connect(class2_object,SIGNAL(change_progress_bar()), this, SLOT(set_progress_bar()));
    4. class2_object->dummy();
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  13. #13
    Join Date
    Feb 2009
    Posts
    143
    Thanks
    8

    Default Re: ui problem

    thanks mate. it helped.

    I have a AMD 2800+ processor with 512mb RAM. I am using win xp.

    But compiling the simple app as above took about 2 minutes.

    Is there any way to increase the speed of compilation?

Similar Threads

  1. Replies: 1
    Last Post: 23rd April 2009, 09:05
  2. Replies: 19
    Last Post: 3rd April 2009, 23:17
  3. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  4. Problem with receiving events from QDateEdit
    By gunhelstr in forum Qt Programming
    Replies: 4
    Last Post: 20th April 2006, 11:21
  5. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36

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
  •  
Qt is a trademark of The Qt Company.