PDA

View Full Version : setVisible, -> token, problems



Salazaar
12th June 2007, 10:54
Hi. I've got some annoying errors which appear in my Dialog.cpp file:

#include <QtGui>

#include "Dialog.h"




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

fromLineEdit->hide();
fromLabel->hide();
whiteLabel->hide();
toLabel->hide();
convertButton->hide();
exitButton_2->hide();


connect(nextStepButton, SIGNAL(clicked()), this, SLOT(settingUp()));

}



bool Dialog::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;
}

}

// And few other which look almost the same



if (beaufortBox->isChecked() && knotBox_2->isChecked())
{
Dialog->setWindowTitle("Converting value from Beaufort to Knot");
toLabel->setText("Knot(s)");
fromLineEdit->hide();
fromLabel->setVisible(bool);
whiteLabel->setVisible(bool);
toLabel->setVisible(bool);
convertButton->setVisible(bool);
exitButton_2->setVisible(bool);
}

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

fromLabel->setVisible(bool);
whiteLabel->setVisible(bool);
toLabel->setVisible(bool);
convertButton->setVisible(bool);
exitButton_2->setVisible(bool);
}

// And others which look almost the same





}






Errors are the same for each if instruction (exeptions are first if's which return false):
In member function bool Dialog::settingUp()
expected primary expression before "bool"
expected primary expression before -> token

I've got much this kind of errors, only the line which the error appears its different. When I was trying to do setVisible() instead of setVisible(bool) I reached errors that candidates are setVisible(bool) and a few others about setVisible()

high_flyer
12th June 2007, 11:30
Am... before coding with a programming language it is recommended to learn that language.
Just as an example which comes all over your code:


fromLabel->setVisible(bool); //<< you are using a mix of decleration and implementation syntax
//should be:
fromLabel->setVisible(true /* or - flase*/);

Salazaar
12th June 2007, 11:42
Thanks, it solved the problem about bool, but I really don't understand what is this "expected primary expression before -> token" about. Regards

high_flyer
12th June 2007, 11:57
Was it the first error you got?
I guess not.
If its not the first error, then it probably means nothing coherent, since the errors that come after the first, might be "built" on the first error, since you didn't supply the compiler error output with line numbers, it really is hard to say.
But gegenrally it means that if you have:

somePointer->someMethog();
Then somePointer needs to be defined, and it is not, or, that its not a pointer that can be agregated. (no inner elements).

Salazaar
12th June 2007, 12:04
[QUOTE=high_flyer;40170]Was it the first error you got?
I guess not.
If its not the first error, then it probably means nothing coherent, since the errors that come after the first, might be "built" on the first error
[quote]
No, it was the first (and only) type of error, not to say error, because I've got many errors which look like this one. Line? Sure:

Dialog->setWindowTitle("Converting value from Beaufort to Knot");
and this is the first line where errors appears, it appears in every Dialog->setWindowTitle() but it doesn't in e.g. toLabel->setText()

wysota
12th June 2007, 12:15
It's exactly what high_flyer said - Dialog is the name of the class, not a pointer to an instance of a class.

Salazaar
12th June 2007, 12:19
Hmm...But when I was looking to ui_Dialog.h code, I saw

Dialog->setWindowTitle(...);
So, I don't understand why it doesn't work in my case

high_flyer
12th June 2007, 12:27
So, I don't understand why it doesn't work in my case
Because you don't know the C++ syntax.
Before using Qt, you should learn C++, and the first step is learning the systax.
You can't code if you don't know the sytax.

Salazaar
12th June 2007, 12:33
I know C++, coauthored many (console) programs. Syntax is very wide definition. I know syntax, but I don't understand why it doesn't work (Don't say: "It means that you don't knot the syntax")

high_flyer
12th June 2007, 12:36
ok, then post ui_Dialog.h code here and I'll show you why it doesn't work when you use Dialog->something(). (all though wysota already answered that)

Syntax is very wide definition
No, its not, its very specific.
http://en.wikipedia.org/wiki/Syntax
and for programming:
http://en.wikipedia.org/wiki/Syntax_of_programming_languages

Salazaar
12th June 2007, 12:41
Ok, here it goes:

/************************************************** ******************************
** Form generated from reading ui file 'Dialog.ui'
**
** Created: Mon 11. Jun 11:28:37 2007
** by: Qt User Interface Compiler version 4.2.3
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
************************************************** ******************************/

#ifndef UI_DIALOG_H
#define UI_DIALOG_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QGroupBox>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QRadioButton>

class Ui_Dialog
{
public:
QGroupBox *groupBox;
QRadioButton *beaufortBox;
QRadioButton *knotBox;
QRadioButton *kphBox;
QRadioButton *mphBox;
QRadioButton *mpsBox;
QGroupBox *groupBox_2;
QRadioButton *beaufortBox_2;
QRadioButton *knotBox_2;
QRadioButton *mpsBox_2;
QRadioButton *kphBox_2;
QRadioButton *mphBox_2;
QLabel *label;
QLabel *salazaarLabel;
QLabel *fromLabel;
QLabel *whiteLabel;
QLabel *toLabel;
QLineEdit *fromLineEdit;
QPushButton *convertButton;
QPushButton *exitButton;
QPushButton *exitButton_2;
QPushButton *nextStepButton;

void setupUi(QDialog *Dialog)
{
Dialog->setObjectName(QString::fromUtf8("Dialog"));
Dialog->setWindowIcon(QIcon(QString::fromUtf8(":/new/prefix1/MainDialogIcon.jpg")));
groupBox = new QGroupBox(Dialog);
groupBox->setObjectName(QString::fromUtf8("groupBox"));
groupBox->setGeometry(QRect(50, 40, 120, 131));
beaufortBox = new QRadioButton(groupBox);
beaufortBox->setObjectName(QString::fromUtf8("beaufortBox"));
beaufortBox->setGeometry(QRect(10, 20, 83, 18));
knotBox = new QRadioButton(groupBox);
knotBox->setObjectName(QString::fromUtf8("knotBox"));
knotBox->setGeometry(QRect(10, 40, 83, 18));
kphBox = new QRadioButton(groupBox);
kphBox->setObjectName(QString::fromUtf8("kphBox"));
kphBox->setGeometry(QRect(10, 80, 83, 18));
mphBox = new QRadioButton(groupBox);
mphBox->setObjectName(QString::fromUtf8("mphBox"));
mphBox->setGeometry(QRect(10, 100, 83, 18));
mpsBox = new QRadioButton(groupBox);
mpsBox->setObjectName(QString::fromUtf8("mpsBox"));
mpsBox->setGeometry(QRect(10, 60, 83, 18));
groupBox_2 = new QGroupBox(Dialog);
groupBox_2->setObjectName(QString::fromUtf8("groupBox_2"));
groupBox_2->setGeometry(QRect(240, 40, 120, 131));
beaufortBox_2 = new QRadioButton(groupBox_2);
beaufortBox_2->setObjectName(QString::fromUtf8("beaufortBox_2"));
beaufortBox_2->setGeometry(QRect(10, 20, 83, 18));
knotBox_2 = new QRadioButton(groupBox_2);
knotBox_2->setObjectName(QString::fromUtf8("knotBox_2"));
knotBox_2->setGeometry(QRect(10, 40, 83, 18));
mpsBox_2 = new QRadioButton(groupBox_2);
mpsBox_2->setObjectName(QString::fromUtf8("mpsBox_2"));
mpsBox_2->setGeometry(QRect(10, 60, 83, 18));
kphBox_2 = new QRadioButton(groupBox_2);
kphBox_2->setObjectName(QString::fromUtf8("kphBox_2"));
kphBox_2->setGeometry(QRect(10, 80, 83, 18));
mphBox_2 = new QRadioButton(groupBox_2);
mphBox_2->setObjectName(QString::fromUtf8("mphBox_2"));
mphBox_2->setGeometry(QRect(10, 100, 83, 18));
label = new QLabel(Dialog);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(80, 20, 71, 16));
salazaarLabel = new QLabel(Dialog);
salazaarLabel->setObjectName(QString::fromUtf8("salazaarLabel"));
salazaarLabel->setGeometry(QRect(20, 410, 275, 16));
salazaarLabel->setAutoFillBackground(false);
salazaarLabel->setFrameShape(QFrame::StyledPanel);
salazaarLabel->setFrameShadow(QFrame::Plain);
salazaarLabel->setTextFormat(Qt::AutoText);
salazaarLabel->setScaledContents(false);
fromLabel = new QLabel(Dialog);
fromLabel->setObjectName(QString::fromUtf8("fromLabel"));
fromLabel->setGeometry(QRect(100, 270, 81, 16));
whiteLabel = new QLabel(Dialog);
whiteLabel->setObjectName(QString::fromUtf8("whiteLabel"));
whiteLabel->setGeometry(QRect(190, 270, 46, 14));
toLabel = new QLabel(Dialog);
toLabel->setObjectName(QString::fromUtf8("toLabel"));
toLabel->setGeometry(QRect(270, 270, 97, 16));
fromLineEdit = new QLineEdit(Dialog);
fromLineEdit->setObjectName(QString::fromUtf8("fromLineEdit"));
fromLineEdit->setGeometry(QRect(40, 270, 51, 20));
convertButton = new QPushButton(Dialog);
convertButton->setObjectName(QString::fromUtf8("convertButton"));
convertButton->setGeometry(QRect(200, 320, 75, 23));
exitButton = new QPushButton(Dialog);
exitButton->setObjectName(QString::fromUtf8("exitButton"));
exitButton->setGeometry(QRect(300, 320, 75, 23));
exitButton_2 = new QPushButton(Dialog);
exitButton_2->setObjectName(QString::fromUtf8("exitButton_2"));
exitButton_2->setGeometry(QRect(290, 190, 75, 23));
nextStepButton = new QPushButton(Dialog);
nextStepButton->setObjectName(QString::fromUtf8("nextStepButton"));
nextStepButton->setGeometry(QRect(160, 190, 91, 23));

retranslateUi(Dialog);

QSize size(400, 426);
size = size.expandedTo(Dialog->minimumSizeHint());
Dialog->resize(size);

QObject::connect(exitButton, SIGNAL(clicked()), Dialog, SLOT(close()));
QObject::connect(exitButton_2, SIGNAL(clicked()), Dialog, SLOT(close()));

QMetaObject::connectSlotsByName(Dialog);
} // setupUi

void retranslateUi(QDialog *Dialog)
{
Dialog->setWindowTitle(QApplication::translate("Dialog", "Wind units converter", 0, QApplication::UnicodeUTF8));
groupBox->setTitle(QApplication::translate("Dialog", "From", 0, QApplication::UnicodeUTF8));
beaufortBox->setText(QApplication::translate("Dialog", "Beaufort", 0, QApplication::UnicodeUTF8));
knotBox->setText(QApplication::translate("Dialog", "Knot", 0, QApplication::UnicodeUTF8));
kphBox->setText(QApplication::translate("Dialog", "Kph", 0, QApplication::UnicodeUTF8));
mphBox->setText(QApplication::translate("Dialog", "Mph", 0, QApplication::UnicodeUTF8));
mpsBox->setText(QApplication::translate("Dialog", "Mps", 0, QApplication::UnicodeUTF8));
groupBox_2->setTitle(QApplication::translate("Dialog", "To", 0, QApplication::UnicodeUTF8));
beaufortBox_2->setText(QApplication::translate("Dialog", "Beaufort", 0, QApplication::UnicodeUTF8));
knotBox_2->setText(QApplication::translate("Dialog", "Knot", 0, QApplication::UnicodeUTF8));
mpsBox_2->setText(QApplication::translate("Dialog", "Mps", 0, QApplication::UnicodeUTF8));
kphBox_2->setText(QApplication::translate("Dialog", "Kph", 0, QApplication::UnicodeUTF8));
mphBox_2->setText(QApplication::translate("Dialog", "Mph", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("Dialog", "Convert units:", 0, QApplication::UnicodeUTF8));
salazaarLabel->setText(QApplication::translate("Dialog", "Salazaar Software Corporation - Speed Units Converter", 0, QApplication::UnicodeUTF8));
fromLabel->setText(QApplication::translate("Dialog", "Beaufort(s) it's", 0, QApplication::UnicodeUTF8));
whiteLabel->setText(QString());
toLabel->setText(QApplication::translate("Dialog", "Meter(s) per second", 0, QApplication::UnicodeUTF8));
convertButton->setText(QApplication::translate("Dialog", "Convert", 0, QApplication::UnicodeUTF8));
exitButton->setText(QApplication::translate("Dialog", "Exit", 0, QApplication::UnicodeUTF8));
exitButton_2->setText(QApplication::translate("Dialog", "Exit", 0, QApplication::UnicodeUTF8));
nextStepButton->setText(QApplication::translate("Dialog", "Go to next step", 0, QApplication::UnicodeUTF8));
Q_UNUSED(Dialog);
} // retranslateUi

};

namespace Ui {
class Dialog: public Ui_Dialog {};
} // namespace Ui

#endif // UI_DIALOG_H

high_flyer
12th June 2007, 12:45
right:
So lets see:


void setupUi(QDialog *Dialog)
{
Dialog->setObjectName(QString::fromUtf8("Dialog"));
// the rest
}

//and your code:
bool Dialog::settingUp()
{
...
Dialog->setWindowTitle("Converting value from Beaufort to Knot");
....
}


Now, since you know C++ syntax, why don't you explain to me the error in your code.
If you can't I will.



coauthored many (console) programs.
I'd be interested to know which ones, would be great if you could supply links.

Salazaar
12th June 2007, 12:56
right:
So lets see:


void setupUi(QDialog *Dialog)
{
Dialog->setObjectName(QString::fromUtf8("Dialog"));
// the rest
}

//and your code:
bool Dialog::settingUp()
{
...
Dialog->setWindowTitle("Converting value from Beaufort to Knot");
....
}


Now, since you know C++ syntax, why don't you explain to me the error in your code.
If you can't I will.



How do you think, why am I asking this question? Obviously because I don't know the answer;)


I'd be interested to know which ones, would be great if you could supply links.

Important? But if you want to know, one was called Professional Friends Database with many useful functions. I don't supply link, because pure C++ programs are history...

high_flyer
12th June 2007, 13:04
How do you think, why am I asking this question? Obviously because I don't know the answer
Well, if you don't know the answer, how can you claim you know C++ syntax?

If you knew C++ then you would know that:



void setupUi(QDialog *Dialog) //<< 'Dialog' pointer is defined.
{

Dialog->setObjectName(QString::fromUtf8("Dialog")); //so this is ok.
// the rest
}


And as wasota gave the answer above:

bool Dialog::settingUp() //Dialog is the name of the class
{
...
Dialog->setWindowTitle("Converting value from Beaufort to Knot"); //pointer 'Dialog' never defined, so Dialog-> is illegal.
....
}


I don't supply link, because pure C++ programs are history...
History??
What do you mean?

wysota
12th June 2007, 13:09
I know syntax, but I don't understand why it doesn't work (Don't say: "It means that you don't knot the syntax")
Based on what I've seen in your posts, I strongly doubt that...


Ok, here it goes:
Next time please attach large amounts of code instead of pasting them directly.


I don't supply link, because pure C++ programs are history...

Well now... I... wouldn't say that.... :eek:

Salazaar
12th June 2007, 13:11
How never defined?? It was defined in first code - QDialog * Dialog. So what's "legal"?
I mean that console program doesn't exist, and I'm not programming purely in C++ but using Qt
edit:
wysota, I meant purely C++, without Qt

high_flyer
12th June 2007, 13:16
It was defined in first code - QDialog * Dialog. So what's "legal"?
Heh???
I don't see that nowhere in your code!
And neither the compiler, so I guess you didn't define QDialog * Dialog.
And in general, even if you have, its bad practice to use the class name as variable name, since it might confuse the compiler.

Salazaar
12th June 2007, 13:28
Lets review

void setupUi(QDialog *Dialog)
So it should work, even if the name is the same as class name

wysota
12th June 2007, 13:33
wysota, I meant purely C++, without Qt

Yes, I meant that as well. 99% of your problems on this forum are C++ syntax problems and not Qt. You can't distinguish between static and non-static methods, objects and classes, you admitted you can't handle subclassing very well, you have problems with understanding scopes and you can't spot a difference between a declaration of an object and a method. All these problems have nothing to do with Qt, they are purely C++ related. Qt is not a language, it's a bunch of classes conforming to the C++ syntax (apart from the "signals", "slots" and "emit" keywords, but these are transparent to C++ compilers).

high_flyer
12th June 2007, 13:36
So it should work, even if the name is the same as class name
No it should not.
Because the decleration does not belong to the scope you are using it in.

Salazaar
12th June 2007, 13:40
Understood. Assuming, what do I have to change in this Dialog->setWindowTitle to make it no-errormaking program?

high_flyer
12th June 2007, 13:51
Define a QDialog pointer instead of Dialog.

Allthough the above is the answer to your question, it will not solve your problem, which is knowing and understanding C++ rules and syntax.
As long as you wont master that, you will have these problems all the time.

Salazaar
12th June 2007, 13:55
Define a QDialog pointer instead of Dialog.


I don't understand, Dialog is a pointer of QDIalog

high_flyer
12th June 2007, 14:09
Not in your code.

Salazaar
12th June 2007, 14:26
void setupUi (QDialog * Dialog)

high_flyer
12th June 2007, 14:30
yes, but I already told you, its not in the scope of your code.
You would have understood that if you knew C++ rules.
We can't teach you C++.
First learn C++, then code Qt.