How can I change the system time from a Qt application? I can change that by hwclock from terminal, but I want to provide a GUI for user. Thanks
set linux system time from Qt
I do it by calling sprintf(buf, "/bin/date -s %04d.%02d.%02d-%02d:%02d", year, month, day, hour, min); system(buf); system("/sbin/hwclock -w"); ... in my user-pressed-the-ok-button slot. Seems to work well enough :)
If I execute the hwclock command I get the error message as 'Only superuser can change the system time' can you please give solution
Which machine are you running this on? What kernel are you using? Can you browse and edit files in root without putting in a password?
Ajiesh, sure. Only the root user can change system settings. Its a feature, not a bug ;) -> "man sudo"
How to become a root user........... I have to change the date and time for phytec board AM335x...... it is possible to change by using qt programming..........
#ifndef SETTING_H #define SETTING_H #include"formula.h" #include <QWidget> #include"dialog.h" #include<QLineEdit> #include<QLabel> class setting : public QDialog { public: setting(); class formula *main_class; QLineEdit *offset; QLineEdit *multiplier; QLineEdit *timeinterval; QLabel *off; QLabel *mul; QLabel *time; QPushButton *Apply; QPushButton *close; public slots: void done_value(); }; #include "setting.h" setting::setting() { main_class = new formula(); offset = new QLineEdit; multiplier = new QLineEdit; timeinterval = new QLineEdit; off = new QLabel("OffSet :"); mul = new QLabel("Multiplier :"); time = new QLabel("TimeInterval:"); QHBoxLayout *h1 = new QHBoxLayout; h1->addWidget(off); h1->addWidget(offset); QHBoxLayout *h2 = new QHBoxLayout; h2->addWidget(mul); h2->addWidget(multiplier); QHBoxLayout *h3 = new QHBoxLayout; h3->addWidget(time); h3->addWidget(timeinterval); Apply = new QPushButton("Apply"); close = new QPushButton("Close"); QHBoxLayout *but = new QHBoxLayout; but->addWidget(Apply); but->addWidget(close); QFont font ; font = off->font(); font.setPointSize(30); off->setFont(font); font = off->font(); font.setPointSize(30); mul->setFont(font); font = off->font(); font.setPointSize(30); time->setFont(font); QVBoxLayout *final = new QVBoxLayout; final->addLayout(h1); final->addLayout(h2); final->addLayout(h3); final->addLayout(but); setLayout(final); QObject::connect(Apply,SIGNAL(clicked()),this,SLOT(done_value())); QObject::connect(close,SIGNAL(clicked()),this,SLOT(close())); } void setting::done_value(){ float f; QString line1 =offset->text(); QTextCodec *codec =QTextCodec::codecForName("KOI8-R"); QByteArray byte1 =codec->fromUnicode(line1); main_class->c = byte1.toFloat(); QString line2 =multiplier->text(); QByteArray byte2 =codec->fromUnicode(line2); main_class->m = byte2.toFloat(); QString line3 =timeinterval->text(); QByteArray byte3 =codec->fromUnicode(line3); main_class-> timeinterval = byte3.toFloat(); this->hide(); } Error:Object::connect: No such slot QDialog::done_value()