I write in header file private slots and the compiler gives an error:
d:\qtproject\new123\mainwindow.h:31: error: C2059: syntax error : 'public'
Please help me. I changed to public but no difference.When I clear 'public/private slots' no error comes , but writes loading D:\Qtproject\new123\debug\new123.exe... QObject::connect: No such slot QPushButton::changed() in main.cpp:18 QObject::connect: No such slot QPushButton::moved() in main.cpp:27
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPushButton>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void changed();
void moved();
signals:
void clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void moved()
{
QPushButton a;
a.move(100,100);
}
void changed()
{ QPushButton g;
g.setStyleSheet("QPushButton { background-color : white; color :blue; }");
}
main.cpp
#include "mainwindow.h"
#include <QApplication>
#include <QLabel>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
QPushButton s("Change Color", &w);
s.setStyleSheet("QPushButton { background-color : white; color :pink; }"
"QPushButton:pressed { color: blue; }");
QObject::connect(&s, SIGNAL(clicked()), &s, SLOT(changed()));
QPushButton d("Quit", &w);
d.setStyleSheet("QPushButton { background-color : white; color :black; }");
QObject::connect(&d, SIGNAL(clicked()), qApp, SLOT(quit()));
d.move(100,0);
QPushButton f("Move Button", &w);
f.move(200,0);
f.setStyleSheet("QPushButton { background-color : white; color :green; }");
QObject::connect(&f, SIGNAL(clicked()), &f, SLOT(moved()));
w.show();
return a.exec();
}