problem with time_t

not quite sure how to use time_t

void Start::on_pushButton_clicked()
{
time_t = time;
if(time == 1930){
cout << "Cleaning is beginning!" << endl;
system("echo 2rvasjrf | sudo -v -S && apt-get update");
system("apt-get upgrade");
system("apt-get dist-upgrade");
system("apt-get clean");
system("apt-get autoremove");
}

else{
cout << "no cleaning required" << endl;
}

this->close();
}
You can use std::localtime (or std::gmtime) to convert the std::time_t into a std::tm struct which contains information about the year, month, etc.

1
2
3
4
5
6
std::time_t t = std::time(nullptr);
std::tm* tm = std::localtime(&t);
if (tm->tm_year == 30)
{
	std::cout << "The year is 1930.\n";
}

http://en.cppreference.com/w/cpp/chrono/c/time
http://en.cppreference.com/w/cpp/chrono/c/localtime
http://en.cppreference.com/w/cpp/chrono/c/tm
im trying to say if the time is 7:30PM then execute code
1
2
if (tm->tm_hour == 19 && 
    tm->tm_min  == 30)


But I'm not sure it will work the way you want. The code just checks the current time and unless you repeatedly keep checking this condition you won't be able to react on a time in the future. Maybe the framework that you're using has some kind of callback mechanism based on time that you can use.
next issue is how do i call a push button from start.cpp in main.cpp that looks like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "mainwindow.h"
#include "start.h"
#include <QApplication>
#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    if(Start::on_pushButton_clicked()) //this is the line with an error
{
  //do stuff
}
    return a.exec();
}


error: cannot call member function 'void Start::on_pushButton_clicked()' without object
if(Start::on_pushButton_clicked())
^
Last edited on
Topic archived. No new replies allowed.