Hi,
Im pretty new to QT, and I tried following a tutorial on youtube (part1, part2) to build a simple timer.
When compiling my code, I get the warning:
Object::connect: No such slot MainWindow::start()
Object::connect: (sender name: 'bt_start')
Object::connect: (receiver name: 'MainWindow')
Here's my code so far:
main.cpp:
#include <QtGui/QApplication>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTimer>
#include "ui_mainwindow.h"
#include <QTGui>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
int hours;
int minutes;
int seconds;
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private:
Ui::MainWindow *ui;
void count();
void start();
void stop();
void reset();
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTimer>
#include "ui_mainwindow.h"
#include <QTGui>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
QTimer *timer;
int hours;
int minutes;
int seconds;
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
void count();
void start();
void stop();
void reset();
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
hours = 1;
minutes = 2;
seconds = 3;
connect(timer, SIGNAL(timeout()), this, SLOT(count()));
connect(ui->bt_start, SIGNAL(clicked()), this, SLOT(start()));
connect(ui->bt_stop, SIGNAL(clicked()), this, SLOT(stop()));
connect(ui->bt_reset, SIGNAL(clicked()), this, SLOT(reset()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::start(){
timer->start(1000);
}
<< And the other functions >>
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
hours = 1;
minutes = 2;
seconds = 3;
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(count()));
connect(ui->bt_start, SIGNAL(clicked()), this, SLOT(start()));
connect(ui->bt_stop, SIGNAL(clicked()), this, SLOT(stop()));
connect(ui->bt_reset, SIGNAL(clicked()), this, SLOT(reset()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::start(){
timer->start(1000);
}
<< And the other functions >>
To copy to clipboard, switch view to plain text mode
It seems the constructor doesn't get loaded properly, becausein the GUI hours/minutes/seconds = 0, while I've set them on different numbers.
Can anyone tell me what I'm doing wrong? Thanks!
Bookmarks