PDA

View Full Version : error: request for member `ok' in `xxx



intek
6th March 2009, 19:35
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

JimDaniel
6th March 2009, 19:42
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?

intek
6th March 2009, 20:08
class Gui : public QObject
{
Q_OBJECT

private:
QVBoxLayout *_layout;
Widget *_widget;
LineEdit *_lineEdit;


public:

Gui () : _layout( new QVBoxLayout() ),
_widget( new Widget() ),
_lineEdit( new LineEdit() )
{
_layout->addWidget( _widget );
_widget->setLayout( _layout );
}

void ok() { }


};

pastor
6th March 2009, 20:24
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".

JimDaniel
6th March 2009, 21:23
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:



//main.cpp
#include <QApplication>
#include "MyGui.h"

int main(int argc, char * argv[])
{
QApplication app(argc, argv);

MyGui test_gui;
test_gui.ok();

return app.exec();
}

//MyGui.h
#include <QtGui>
class MyGui : public QWidget
{
Q_OBJECT

public:
MyGui();
~MyGui();

void ok();

private:
QLineEdit * m_line_edit;
};

//MyGui.cpp
#include "MyGui.h"

MyGui::MyGui()
{
m_line_edit = new QLineEdit();

QVBoxLayout * layout = new QVBoxLayout();
layout->addWidget(m_line_edit);

setLayout(layout);
}

MyGui::~MyGui(){}

void MyGui::ok()
{
m_line_edit->setText("Everything is OK!");
}

intek
6th March 2009, 21:54
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.



void Show() {
QDialog dlg;
... (include line edit)
dlg.show
}


Thanks!

JimDaniel
6th March 2009, 22:16
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:


MyGui::showDialog()
{
QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
tr("User name:"), QLineEdit::Normal,
QDir::home().dirName(), &ok);
//do something with text...
}


I just took that from the documentation example.