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
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
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?
Qt Code:
{ Q_OBJECT private: QVBoxLayout *_layout; Widget *_widget; LineEdit *_lineEdit; public: _widget( new Widget() ), _lineEdit( new LineEdit() ) { _layout->addWidget( _widget ); _widget->setLayout( _layout ); } void ok() { } };To copy to clipboard, switch view to plain text mode
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".
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:
//main.cpp #include <QApplication> #include "MyGui.h" int main(int argc, char * argv[]) { MyGui test_gui; test_gui.ok(); return app.exec(); } //MyGui.h #include <QtGui> { Q_OBJECT public: MyGui(); ~MyGui(); void ok(); private: QLineEdit * m_line_edit; }; //MyGui.cpp #include "MyGui.h" MyGui::MyGui() { layout->addWidget(m_line_edit); setLayout(layout); } MyGui::~MyGui(){} void MyGui::ok() { m_line_edit->setText("Everything is OK!"); }To copy to clipboard, switch view to plain text mode
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:
void Show() { QDialog dlg; ... (include line edit) dlg.show }To copy to clipboard, switch view to plain text mode
Thanks!
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:
MyGui::showDialog() { //do something with text... }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