The program has unexpectedly finished
-
[quote author="MuldeR" date="1335483291"]
The name of your pointer variables doesn't matter. It matters that you store the right pointer![/quote]In fact, we can use the same name even without this
@
Stopwatch::Stopwatch(Ui::Clock_Application *ui)
:ui(ui)
{
//this->ui = ui;
@But as I said in previous post, current design is rather bad. it will made the application more complex and difficult to maintain.
[quote author="Flurite" date="1335480406"]
I am going to have more slots in my application, and I just do not want to clutter up the Clock_Application class.. I think by dividing it into multiple files will make it simpler.
[/quote] -
I agree.
If possible, the Stopwatch class shouldn't need to know about the whole Ui::Clock_Application class. I'd prefer to only pass a pointer to a QLabel object (or whatever type the Stopwatch_Output is) around, which makes the Stopwatch class more general, more reusable and less likely to be effected by changes in "far away" code...
(But I wouldn't say that wrapping the "Stopwatch" functionality into its own class is bad per se. An alternative worth considering would be making the Stopwatch class inherit from QLabel or another Widget class though)
@class Stopwatch : public QObject
{
Q_OBJECTpublic:
Stopwatch(QLabel *output);...
private:
QTimer* stopwatchTimer;
QLabel *m_output; //here we'll store the pointer to the Widget
};...
Stopwatch::Stopwatch(QLabel *output)
{
m_output = output; //Now store the pointer to the Widget
stopwatchTimer = 0;
}...
void Stopwatch::timer_Reset()
{
timer_Pause();
output->setText("00:00:00");
}@@ Clock_Application::Clock_Application(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Clock_Application)
{
ui->setupUi(this);myStopwatch = new Stopwatch(ui->Stopwatch_Output); // <--- pass Widget ....@
-
I remember that the timer must be stopped before closing the window, i had that problem before, and i resolved it by calling the 'stop' method when the program is closing.