PDA

View Full Version : Few general problems



Salazaar
11th June 2007, 20:56
Hi. I've got some problems with my program code. Here it goes:
ConvertDialog.h:

#ifndef CONVERTDIALOG_H
#define CONVERTDIALOG_H

#include "ui_ConvertDialog.h"



class convertDialog : public QDialog, public Ui::convertDialog
{
Q_OBJECT

public:
convertDialog(QWidget *parent = 0);

public slots:

bool settingUp();


private:

Ui::convertDialog ui;
};

#endif


Dialog.h

#ifndef DIALOG_H
#define DIALOG_H

#include "ui_dialog.h"



class Dialog : public QDialog, public Ui::Dialog
{
Q_OBJECT

public:
Dialog(QWidget *parent = 0);

void displayConvertDialog();





private:

Ui::Dialog ui;
};

#endif

Salazaar
11th June 2007, 20:58
Dialog.cpp

#include <QtGui>

#include "Dialog.h"
#include "ConvertDialog.h"



Dialog::Dialog(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);

connect(pushButton, SIGNAL(clicked()), this, SLOT(convertDialog::settingUp()));

}


convertDialog(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);

}

bool convertDialog::settingUp()
{
if (beaufortBox->isChecked() && beaufortBox_2->isChecked())
{
int ret = QMessageBox::information(this, tr("Speed Units Converter"),
tr("You can't convert value to the same unit"),
QMessageBox::Ok | QMessageBox::Default);
if (ret == QMessageBox::Ok)
{
return false;
}

}

if (knotBox->isChecked() && knotBox_2->isChecked())
{
int ret = QMessageBox::information(this, tr("Speed Units Converter"),
tr("You can't convert value to the same unit"),
QMessageBox::Ok | QMessageBox::Default);
if (ret == QMessageBox::Ok)
{
return false;
}

}

if (mpsBox->isChecked() && mpsBox_2->isChecked())
{
int ret = QMessageBox::information(this, tr("Speed Units Converter"),
tr("You can't convert value to the same unit"),
QMessageBox::Ok | QMessageBox::Default);
if (ret == QMessageBox::Ok)
{
return false;
}

}

if (kphBox->isChecked() && kphBox_2->isChecked())
{
int ret = QMessageBox::information(this, tr("Speed Units Converter"),
tr("You can't convert value to the same unit"),
QMessageBox::Ok | QMessageBox::Default);
if (ret == QMessageBox::Ok)
{
return false;
}

}

if (mphBox->isChecked() && mphBox_2->isChecked())
{
int ret = QMessageBox::information(this, tr("Speed Units Converter"),
tr("You can't convert value to the same unit"),
QMessageBox::Ok | QMessageBox::Default);
if (ret == QMessageBox::Ok)
{
return false;
}



}


if (beaufortBox->isChecked() && knotBox_2->isChecked())
{
convertDialog->setWindowTitle("Converting value from Beaufort to Knot");
toLabel->setText("Knot(s)");
Dialog::displayConvertDialog();
}

if (beaufortBox->isChecked() && mpsBox_2->isChecked())
{
convertDialog->setWindowTitle("Converting value from Beaufort to Mps");

Dialog::displayConvertDialog();
}

/...and many the same looking
}

if (mphBox->isChecked() && kphBox_2->isChecked())
{
convertDialog->setWindowTitle("Converting value from Kph to Kph");
fromLabel->setText("Mile(s) per hour it's");
toLabel->setText("Kilometer(s) per hour");
Dialog::displayConvertDialog();
}



}

void Dialog::displayConvertDialog()
{
convertDialog dlg( this );

dlg.exec();
}




and also ui_Dialog.h, ui_ConvertDialog.h and main.cpp which contents are obvious. Here are those problems:
Dialog.cpp:18:error: expected ) before * token
Dialog.cpp:18:error: expected , or ; before * token
In bool convertDialog.h:
beaufortBox undeclared (and the same with others e.g. knotBox)
Dialog.cpp:99:error: expected primary expression before -> token (im reporting about it only once, I've got much errors like this)
Dialog.cpp:94:error cannot call member function void Dialog::displayConvertDialog() without object

When I try to solve the undeclared e.g. knotBox by calling Dialog::knotBox I reach error that undefined reference to Ui::Dialog or something like this because I didn't call the same to ui part of this class. How to solve all this problems? Regards
p.s. I had to split the text between 2 posts

wysota
13th June 2007, 07:59
Without knowing how the convertDialog class is declared we can't help you much. But generally you have syntax problems (again). You're calling a non-static method as static (again) and I suspect "convertDialog" doesn't have a constructor that takes a QWidget pointer as its argument.

pdolbey
13th June 2007, 20:04
Just the result of eyeballing the code

Line 18 of Dialog.cpp should read


convertDialog::convertDialog(QWidget *parent)


I can't tell if you're using the "is a" multiple inheritance model, or the "has a" single inheritance model for your GUI components as the header files show both implemented.

see http://doc.trolltech.com/4.3/designer-using-a-component.html

If your using the "has a" implementation, you probably need to use the "ui.beaufortBox->isChecked()" form etc, assuming this is defined in your ui file - if you're using the "is a" then you don't use ui.setupUI(this), just "setupUI(this)" and so on...

Pete

Gopala Krishna
13th June 2007, 20:57
Why dont you learn c++ first ? Most of your recent problems has to do with c++.
Well if this suggestion makes you annoyed, please ignore (which you've been doing till now). The following is just for fun.

bool writeQtCode()
{
if(youDontKnowC++) {
qWarning("Please learn c++! Or use the language you know and which also has qt bindings.");
return false;
}
if(youDontKnowQt) {
qWarning("Use qt assistant and you can also ask in qtcentre");
} //yup no return ;)
//continue coding
}

Salazaar
13th June 2007, 21:17
Really funny, but you don't know if I knew C++. Maybe I just didn't use classes so I've got problems with them? Didn't you think about it?

Gopala Krishna
13th June 2007, 21:33
Really funny, but you don't know if I knew C++. Maybe I just didn't use classes so I've got problems with them? Didn't you think about it?

See, i don't want to underestimate anyone. After all even i was a c++ novice 3 yrs ago. As wysota told, you should have just used c. Lets not debate about that.
I could see in one of your post that you had started to learn c++(i mean classes). Thats nice of you but please do read it in depth, execute sample codes and write some c++ code(not qt) until you can solve most of the syntax errors yourself.
One more suggestion. Read this book if you can get it
Teach yourself c++, Herbert Schildt

Salazaar
13th June 2007, 21:46
Yeah, I started learning classes in depth because I didn't look at this chapter in depth at the beginning because I just didn't used it, they weren't useful for me (yeah, I know it's stupid) but I just didn't feel the advantage that classes give. Anyway

wysota
13th June 2007, 21:54
As wysota told, you should have just used c.
I didn't say he should have used C. I said (or at least meant) that using a C++ compiler with C semantics doesn't yet mean you're programming in C++.


One more suggestion. Read this book if you can get it
Teach yourself c++, Herbert Schildt
He already has a nice book for beginners in his native language. If he sticks to it (implementing some simple apps underway), he should be fine. He just has to read it and not only own it.

@Salazaar: If you have written an application in C++ without using a single class, then it means you don't know C++, sorry... I know some Chinese words, but that doesn't yet mean I can speak Chinese (nor can I say I know the language).

C++ is an object oriented language, whereas you were using the functional approach which is appropriate for functional languages such as C. It's like you were "flying a plane" by driving it on the ground. Sure it's possible, but that's not flying (and it's impractical).

pdolbey
13th June 2007, 22:44
...but I just didn't feel the advantage that classes give. Anyway

So I get the feeling that my last post has fallen on stony ground...

Pete