Results 1 to 15 of 15

Thread: What does this command mean?

  1. #1
    Join Date
    Mar 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    9

    Default What does this command mean?

    Hello everyone, I'm a newbie. Im learning QT language with the "C++ GUI programming with Qt4". I don't really know about the following command:

    Qt Code:
    1. class SortDialog : public QDialog, public Ui::SortDialog
    To copy to clipboard, switch view to plain text mode 

    Anyone tell me what does it mean. Thanks alot.
    A SortDialog dialog had been designed before.
    Last edited by mr.dct; 19th March 2010 at 03:05.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: What does this command mean?

    This is not about Qt... its about C++
    class SortDialog : public QDialog, public Ui::SortDialog
    it says SortDialog is a class which inherits QDialog class and Ui::SortDialog class.

    Ui is a namespace, and Ui::SortDialog is the class in the namespace Ui.
    Basically this class must be designed in designer and then code created with uic.

    Have you designed it ? If yes, would suggest to change design,,, because inheriting from two dialogs doesnt make sense..does it ?
    You could very well had Ui::SortDialog inherited from QDialog, and SortDialog from Ui::SortDialog.

  3. The following user says thank you to aamer4yu for this useful post:

    mr.dct (19th March 2010)

  4. #3
    Join Date
    Mar 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    9

    Default Re: What does this command mean?

    Thanks for your reply.
    By your meaning, I should have Ui::SortDialog inherited from QDialog. So how can I have it.
    Cause I designed the Dialog with the Qt Designer and then qmake will create the header file automatically.
    Can I hand-code this file or It will automatically inherited the QDialog class.
    P/S: I'm not good at English. So if I make some typing error, grammar error, etc... pls let me know.

  5. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: What does this command mean?

    You can do something like in your header file -
    Qt Code:
    1. #include "ui_mainWidget.h"
    2. class MainWindow : public QMainWindow
    3. {
    4. Q_OBJECT
    5.  
    6. private:
    7. Ui::MainWindow ui; // Ui::Mainwindow is the class name you gave to the widget in designer. check ui_****.h file when uic is run over .ui file.
    8. public:
    9. MainWindow();
    10. };
    To copy to clipboard, switch view to plain text mode 

    and in cpp -

    Qt Code:
    1. MainWindow::MainWindow()
    2. {
    3. ui.setupUi(this);
    4. }
    To copy to clipboard, switch view to plain text mode 

    Also search examples in Qt Demos... I guess you will find some example how they have used .ui file

  6. The following user says thank you to aamer4yu for this useful post:

    mr.dct (19th March 2010)

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

    Default Re: What does this command mean?

    Quote Originally Posted by aamer4yu View Post
    Have you designed it ? If yes, would suggest to change design,,, because inheriting from two dialogs doesnt make sense..does it ?
    Ui::SortDialog is not a dialog, it's a Designer form class. The construct quoted is perfectly valid
    You could very well had Ui::SortDialog inherited from QDialog, and SortDialog from Ui::SortDialog.
    No, this wouldn't work.
    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. The following user says thank you to wysota for this useful post:

    mr.dct (19th March 2010)

  9. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: What does this command mean?

    No, this wouldn't work.
    Yea, not exactly the statement. I guess i wrote in a hurry...
    What I meant was like the example I posted, instead of inheriting from 2 classes, one can inherit from one, and setup the ui from the uic generated code.

  10. The following user says thank you to aamer4yu for this useful post:

    mr.dct (19th March 2010)

  11. #7
    Join Date
    Mar 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    9

    Default Re: What does this command mean?

    Hi aamer4yu. I tried to do like you sad but it return this:

    Qt Code:
    1. #include <QMainWindow>
    2. #include "ui_ShapeChangingDialog.h"
    3.  
    4. class ShapeChangingDialog : public QMainWindow
    5. {
    6. Q_OBJECT
    7. public:
    8. ShapeChangingDialog(QWidget *parent = 0);
    9. void setColumnRange(QChar first, QChar last);
    10. private:
    11. Ui::ShapeChangingDialog ui;
    12. }
    To copy to clipboard, switch view to plain text mode 
    ;

    Qt Code:
    1. ShapeChangingDialog.h:14: error: ‘ShapeChangingDialog’ in namespace ‘Ui’ does not name a type
    To copy to clipboard, switch view to plain text mode 

    Can you help me fix this. Thanks !

  12. #8
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: What does this command mean?

    Whats the object name you have given to the widget in your .ui file ? The class type and object name must match.
    For example for above code, in designer you will need to create a QMainWindow, and the object name must be ShapeChangingDialog
    just see some example and play with them.

  13. The following user says thank you to aamer4yu for this useful post:

    mr.dct (20th March 2010)

  14. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: What does this command mean?

    Hi,

    since you don't have basic knowledge of C++, I would advice you first to learn the basics of C++. Till then stay with the code Qt creator designs for you because it works and in for normal use cases it is perfect.
    If you understand to a later time what all means (and aamer4yu has explained it for you in his first reply) then you can change things. But right now it don't make sense just to add somewhere "Dialog" without understanding what is does.

    Lykurg

  15. The following user says thank you to Lykurg for this useful post:

    mr.dct (20th March 2010)

  16. #10
    Join Date
    Mar 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    9

    Default Re: What does this command mean?

    Actually I had learn C++ 2 years ago. On that day, I work with VC++ to make an Image Compressing Application for my project. Till now, I have ever work with with it again. Hence most of them go out of my memory. Now in my new project, I must work with Asterisk and Application in Redhat, so I learn Qt. Your advice is absolutely right. At the beginning I though like you sad, but I feel it will take more time than to learn both of them together. Maybe I must review C++ again. Thanks.
    @aamer4yu: Actually, I designed an Dialog named ShapeChangingDialog before, then I hand-code for it like you sad but I created a subclass of QDialog, not QMainWindow. It still don't work. The qmake had automatically create a ui_ShapeChangingDialog.h header file so it means the name of my dialog is absolutely match with the class.

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

    Default Re: What does this command mean?

    Quote Originally Posted by mr.dct View Post
    The qmake had automatically create a ui_ShapeChangingDialog.h header file so it means the name of my dialog is absolutely match with the class.
    Qt qmake will do this if there is a Designer form file listed in the the pro file FORMS variable. If you want to hand code your forms than don't use Designer or the FORMS variable.

  18. The following user says thank you to ChrisW67 for this useful post:

    mr.dct (23rd March 2010)

  19. #12
    Join Date
    Mar 2010
    Location
    Bangalore, India
    Posts
    4
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: What does this command mean?

    Hi,

    I think your are referring to the example in book "C++ GUI Programming with Qt 4, Second Edition" Creating Dialogs - Shape-Changing Dialogs. Its mentioned in the book "The generated ui_gotocelldialog.h file contains the definition of the Ui::GoToCellDialog class, which is a C++ equivalent of the gotocelldialog.ui file. The class declares member variables that store the form's child widgets and layouts, and a setupUi() function that initializes the form."

    Thus, bascially the line "class SortDialog : public QDialog, public Ui::SortDialog" means you are inheriting both from "QDialog" (provides the Dialog functionality to your object) and "Ui::SortDialog" (provides the setup of your 'dialog' object).
    Therefore, in "sortdialog.cpp", you can see in the contructor of "SortDialog",

    Qt Code:
    1. SortDialog::SortDialog(QWidget *parent)
    2. : QDialog(parent)
    3. {
    4. setupUi(this); // This call is made to initialze and setup the dialog
    To copy to clipboard, switch view to plain text mode 

    and you can see in "ui_gotocelldialog.h", the definition of "setupUi(QDialog *SortDialog)". In this, to the dialog object, various objects are added viz. labels, buttons, etc. Also, layouts for proper layout of GUI objects added, etc.

    If you want to hand-code the setup of your dialog says adding various GUI elements, adding proper layout, etc. then you don't need the "Ui::SortDialog" (You can do this in the constructor of your object itself). This is created if your using the RAD tool "Qt Designer" which is a GUI tool to create UI forms.

    Hope this help.

    Regards,
    Azhar

  20. The following user says thank you to azharbk for this useful post:

    mr.dct (23rd March 2010)

  21. #13
    Join Date
    Mar 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    9

    Default Re: What does this command mean?

    Thanks to Azhar, I've review the ui_ShapeChangingDialog.h file and solve my problem. The class that Ui tool creates is shapeChangingDialog not ShapeChangingDialog. I make a mistake when typing the ObjectName. I also understand deeper about many other thing when reading this file. Thanks everyone.

  22. #14
    Join Date
    Mar 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    9

    Default Re: What does this command mean?

    I have another problem but about Qt Desinger. When I use the QGroupBox, it has no border like in that example. I tried to set "
    Qt Code:
    1. border:1px solid rgb(x,x,x);
    To copy to clipboard, switch view to plain text mode 
    " but it return a border with sqare edge, not curve edge like in the book. I though must use border-radius parameter but it didn't work too. Someone help me to set the right command, and make it the default style when creating a groupbox ??? Thanks.
    Attached Images Attached Images
    Last edited by mr.dct; 23rd March 2010 at 10:49.

  23. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: What does this command mean?

    The example in the book probably uses a different widget style than your system. You can preview the form in Designer in different styles by choosing an appropriate entry from the "Form/Preview in" menu.
    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.


  24. The following 2 users say thank you to wysota for this useful post:

    azharbk (24th March 2010), mr.dct (24th March 2010)

Similar Threads

  1. Replies: 7
    Last Post: 20th October 2012, 14:44
  2. Replies: 4
    Last Post: 14th July 2009, 04:27
  3. SQL command and QString?
    By SunnySan in forum Newbie
    Replies: 9
    Last Post: 11th September 2008, 23:56
  4. When I send a command in QT
    By espariz in forum Newbie
    Replies: 1
    Last Post: 20th June 2006, 21:15
  5. how to use cat command in QProcess
    By renjithmamman in forum Qt Programming
    Replies: 4
    Last Post: 27th January 2006, 19:46

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.