Results 1 to 7 of 7

Thread: error: request for member `ok' in `xxx

  1. #1
    Join Date
    Mar 2009
    Posts
    5

    Default error: request for member `ok' in `xxx

    Very new to QT:

    error: request for member `ok' in `xxx', which is of non-class type `xxx ()()'

    What does this mean?

    I'm just trying this:

    xxx x();

    x.ok();

    thanks

  2. #2
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: error: request for member `ok' in `xxx

    I have some general programming advice for you. Start naming your classes and methods with more descriptive names. It makes things far easier to understand - for you and for others reading your code.

    I need to see your class, but it sounds like ok(); is not a member of your class. Can you copy it here?

  3. #3
    Join Date
    Mar 2009
    Posts
    5

    Default Re: error: request for member `ok' in `xxx

    Qt Code:
    1. class Gui : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. private:
    6. QVBoxLayout *_layout;
    7. Widget *_widget;
    8. LineEdit *_lineEdit;
    9.  
    10.  
    11. public:
    12.  
    13. Gui () : _layout( new QVBoxLayout() ),
    14. _widget( new Widget() ),
    15. _lineEdit( new LineEdit() )
    16. {
    17. _layout->addWidget( _widget );
    18. _widget->setLayout( _layout );
    19. }
    20.  
    21. void ok() { }
    22.  
    23.  
    24. };
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Oct 2008
    Posts
    70
    Thanks
    1
    Thanked 9 Times in 9 Posts

    Default Re: error: request for member `ok' in `xxx

    1) Did you include header with GUI class declaration?
    2) Try this code:

    xxx x;
    x.ok();

    xxx x(); - this is function declaration which gets "void" and returns "xxx".

  5. #5
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: error: request for member `ok' in `xxx

    It seems to me you are going about this a bit wrong. I'm not sure, but take a look at this program which I think does something like what you intend:

    Qt Code:
    1. //main.cpp
    2. #include <QApplication>
    3. #include "MyGui.h"
    4.  
    5. int main(int argc, char * argv[])
    6. {
    7. QApplication app(argc, argv);
    8.  
    9. MyGui test_gui;
    10. test_gui.ok();
    11.  
    12. return app.exec();
    13. }
    14.  
    15. //MyGui.h
    16. #include <QtGui>
    17. class MyGui : public QWidget
    18. {
    19. Q_OBJECT
    20.  
    21. public:
    22. MyGui();
    23. ~MyGui();
    24.  
    25. void ok();
    26.  
    27. private:
    28. QLineEdit * m_line_edit;
    29. };
    30.  
    31. //MyGui.cpp
    32. #include "MyGui.h"
    33.  
    34. MyGui::MyGui()
    35. {
    36. m_line_edit = new QLineEdit();
    37.  
    38. QVBoxLayout * layout = new QVBoxLayout();
    39. layout->addWidget(m_line_edit);
    40.  
    41. setLayout(layout);
    42. }
    43.  
    44. MyGui::~MyGui(){}
    45.  
    46. void MyGui::ok()
    47. {
    48. m_line_edit->setText("Everything is OK!");
    49. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Mar 2009
    Posts
    5

    Default Re: error: request for member `ok' in `xxx

    Jim, that looks great, but how do I show a dialog with the lineedit. I want the gui object to have a function called Show() so I can call that in the main.

    Qt Code:
    1. void Show() {
    2. QDialog dlg;
    3. ... (include line edit)
    4. dlg.show
    5. }
    To copy to clipboard, switch view to plain text mode 

    Thanks!

  7. #7
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: error: request for member `ok' in `xxx

    It sounds like you need to inherit from QDialog and make your own dialog box with a line edit. Then you create a method within your main window called showDialog() or something. You don't want to use show() as QWidget already has a method called show(); Then inside showDialog() you would either create the Dialog object as a non-modal or modal dialog. Does that make sense? I'm not sure I'm explaining it well.

    Also, Qt provides a handful of standard pre-built dialogues that you may not be aware of: QFileDialog, QInputDialog, QProgressDialog, QFontDialog, QColorDialog
    So inside showDialog() you could do this:
    Qt Code:
    1. MyGui::showDialog()
    2. {
    3. QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
    4. tr("User name:"), QLineEdit::Normal,
    5. QDir::home().dirName(), &ok);
    6. //do something with text...
    7. }
    To copy to clipboard, switch view to plain text mode 

    I just took that from the documentation example.
    Last edited by JimDaniel; 6th March 2009 at 21:20.

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.