Hello, i'm a total noob to QT, but i'm really into learning it.
Been trying to solve this by myself for some time now, and i think i'm close now, but still, i'm at a complete loss here.
If someone could help me out, the idea is making a 'guess the number' kind of program, i managed to get the layout done and all, i'm now trying to add some functionality. The first thing i'm trying to implement is that the NewGame button make the infoLabel change it's value.
By now, i managed to understand how to do it, and implemented a function to do so, but when i compile, the compiler won't recognize the class i created to store the function calls.
I'll post here the code, followed by the compiler's output:
#include <QtGui>
#include <QtCore>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QString>
int randgen(int);
int randgen(int x){
x = rand() % 100 + 1;
return x;};
{
public:
};
{
Q_OBJECT
public:
void newClicked();
public slots:
;};
void MyFunctions::newClicked()
{
};
MyWidget
::MyWidget(QWidget *parent
) {
window->setWindowTitle("Guess the number");
spin->setRange(0, 100);
spin->setValue(0);
info->setAutoFillBackground(true);
info->setText(infotext);
input->addWidget(choose);
input->addWidget(spin);
leftLayout->addLayout(input);
leftLayout->addWidget(info);
rightLayout->addWidget(newGame);
rightLayout->addWidget(guess);
layout->addLayout(leftLayout);
layout->addLayout(rightLayout);
window->setLayout(layout);
// info->setText("info here");
connect(newGame, SIGNAL(clicked()), MyFunctions, SLOT(newClicked()));
window->show();
};
/*void MyWidget::newClicked()
{
QString infotext = "NewGameText";
};*/
int main(int argc, char *argv[])
{
MyWidget widget;
return app.exec();
}
#include <QtGui>
#include <QtCore>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QString>
QString infotext = "";
int randgen(int);
int randgen(int x){
x = rand() % 100 + 1;
return x;};
class MyWidget : public QWidget
{
public:
MyWidget(QWidget *parent = 0);
};
class MyFunctions : public QWidget
{
Q_OBJECT
public:
void newClicked();
public slots:
;};
void MyFunctions::newClicked()
{
QString infotext = "NewGame_Text";
};
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
QWidget *window = new QWidget;
window->setWindowTitle("Guess the number");
QLabel *choose = new QLabel("Choose a number");
QSpinBox *spin = new QSpinBox;
spin->setRange(0, 100);
spin->setValue(0);
QLabel *info = new QLabel;
info->setAutoFillBackground(true);
info->setText(infotext);
QPushButton *newGame = new QPushButton("New Game");
QPushButton *guess = new QPushButton("Guess");
QHBoxLayout *input = new QHBoxLayout;
input->addWidget(choose);
input->addWidget(spin);
QVBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addLayout(input);
leftLayout->addWidget(info);
QVBoxLayout *rightLayout = new QVBoxLayout;
rightLayout->addWidget(newGame);
rightLayout->addWidget(guess);
QHBoxLayout *layout = new QHBoxLayout;
layout->addLayout(leftLayout);
layout->addLayout(rightLayout);
window->setLayout(layout);
// info->setText("info here");
connect(newGame, SIGNAL(clicked()), MyFunctions, SLOT(newClicked()));
window->show();
};
/*void MyWidget::newClicked()
{
QString infotext = "NewGameText";
};*/
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyWidget widget;
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Compiler's Output:
guess.
cpp: In constructor ‘MyWidget
::MyWidget(QWidget*)’
:guess.cpp:72: error: expected primary-expression before ‘,’ token
make: *** [guess.o] Error 1
guess.cpp: In constructor ‘MyWidget::MyWidget(QWidget*)’:
guess.cpp:72: error: expected primary-expression before ‘,’ token
make: *** [guess.o] Error 1
To copy to clipboard, switch view to plain text mode
Don't know what's wrong.
Thanks in advance.
Bookmarks