Details
-
Bug
-
Resolution: Unresolved
-
P1: Critical
-
None
-
6.7.1
-
None
-
freebsd 14.1
Description
I run the program lock screen rest some month found this bug.I have compile the code use qt5.15.13 and qt6.7.1 the two version have same bug.
sometime run activateWindow in freebsd system will die. I have restart freebsd many times by this bug.
I try to move activateWIndow function to outside ontimer. but it always make system can not use mouse and keyboard.
this is the code:
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <QFile>
#include <QSystemSemaphore>
#include <QDateTime>
#include <QInputDialog>
#include <QCloseEvent>
#include <QList>
#include <QRegularExpression>
struct TimeDef
{ QString def; QString lock; //lock or unlock; int begin_hour; int begin_minute; int end_hour; int end_minute; int beginsecs; int endsecs; };
QList<TimeDef*> allDef;
QString xxminute="";
int alwaysshow = 0;
QString password;
int fullscreen=0;
int maxscreen=1;
int keyboardallow = 1;
int alpha = 200;
int hotkeyallow = 1;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
QFile ff("LockScreenRest.conf");
QString ffctt;
if(ff.exists()==false)
else
{ ff.open(QFile::OpenModeFlag::ReadOnly); auto bs=ff.readAll(); ffctt=bs; ff.close(); }QStringList sslis=ffctt.split(QRegularExpression("[\r\n]",QRegularExpression::DotMatchesEverythingOption|QRegularExpression::CaseInsensitiveOption|QRegularExpression::MultilineOption));
QString hotkey="X";
for (int si=0;si<sslis.size();si+=1) {
auto lin=sslis[si].trimmed();
if (lin.size() > 0) {
if (lin[lin.size() - 1] == '\r')
if (lin.size() > 0 && lin[0] != '#' && lin.indexOf("lock ")!=1 && lin.indexOf('')!=-1 && lin.indexOf(':')!=-1 && (lin.size()==16 || lin.size()==18))
else if (lin.indexOf("=") != -1 && lin.mid(0, lin.indexOf("=")+1) == "#hotkey=")
{ hotkey = lin.mid(lin.indexOf("=")+1); }else if (lin.indexOf("=")!=-1 && lin.mid(0, lin.indexOf("=") + 1) == "#keyboardallow=")
{ keyboardallow = lin.mid(lin.indexOf("=") + 1).toInt(); }else if (lin.indexOf("=")!=-1 && lin.mid(0, lin.indexOf("=")+1) == "#alpha=")
{ alpha = lin.mid(lin.indexOf("=")+ 1).toInt(); }else if (lin.indexOf("=")!=-1 && lin.mid(0, lin.indexOf("=")+1) == "#hotkeyallow=")
{ hotkeyallow = lin.mid(lin.indexOf("=")+ 1).toInt(); }else if (lin.indexOf("=") != -1 && lin.mid(0, lin.indexOf("=")+1) == "#password=")
{ password = lin.mid(lin.indexOf("=")+1); }else if (lin.indexOf("=") != -1 && lin.mid(0, lin.indexOf("=")+1) == "#fullscreen=")
{ fullscreen = lin.mid(lin.indexOf("=")+ 1).toInt(); }else if (lin.indexOf("=") != -1 && lin.mid(0, lin.indexOf("=")+1) == "#maxscreen=")
{ maxscreen = lin.mid(lin.indexOf("=")+ 1).toInt(); } }
}
connect(this,SIGNAL(showui(QString,int,int)),this,SLOT(Showui(QString,int,int)));
connect(this,SIGNAL(showui2(QString,int,int)),this,SLOT(Showui2(QString,int,int)));
connect(this,SIGNAL(hideui(QString,int,int)),this,SLOT(Hideui(QString,int,int)));
connect(this,SIGNAL(hideui2(QString,int,int)),this,SLOT(Hideui2(QString,int,int)));
connect(&locktimer,SIGNAL(timeout()),this,SLOT(locktimer_timeout()));
locktimer.start(10000);
}
extern QSystemSemaphore semap;
MainWindow::~MainWindow()
void MainWindow::Showui(QString def,int beginsecs,int endsecs){
if(this->isHidden()){
if(maxscreen==1){
if(this->isHidden() || this->isMaximized()==false)
}else if(fullscreen==1){ this->showFullScreen(); }else{ this->showNormal(); }
this->activateWindow();
//this->setWindowFlag(Qt::WindowStaysOnTopHint);
}else{ this->activateWindow(); }
QString minutenum=QString("%1").arg((endsecs - beginsecs) / 60);
ui->msgl->setText("Take A Rest "+minutenum +" Minute");
QDateTime dt=QDateTime::currentDateTime();
auto curts=dt.toString("yyyy-MM-ddThh:mm:ss");
ui->resttime->setText(QString("Rest time:")def" Now:"+curts);
}
void MainWindow::Showui2(QString def,int beginsecs,int endsecs){
if(this->isHidden()){
if(maxscreen==1)
}else if(fullscreen==1)
{ this->showFullScreen(); }else
{ this->showNormal(); } this->activateWindow();
//this->setWindowFlag(Qt::WindowStaysOnTopHint);
}else
QString minutenum=QString("%1").arg((endsecs - beginsecs) / 60);
ui->msgl->setText("Alt+F4 Close Window For Working "+minutenum +" Minutes");
QDateTime dt=QDateTime::currentDateTime();
auto curts=dt.toString("yyyy-MM-ddThh:mm:ss");
ui->resttime->setText(QString("Now work time:")def" Now:"+curts);
}
void MainWindow::Hideui(QString def,int beginsecs,int endsecs){
this->hide();
xxminute = "";
//if (this->isHidden()==false)
}
void MainWindow::Hideui2(QString def,int beginsecs,int endsecs){
this->hide();
xxminute = "";
//if (this->isHidden()==false)
}
bool unlockuntilnextunlock=false;
bool lockuntiluserclose=false;
void MainWindow::locktimer_timeout()
{
if (allDef.size() == 0) {
if (this->isMaximized())
}else {
time_t now;
time(&now);
auto date = localtime(&now);
auto cursecs = date->tm_hour * 3600 + date->tm_min * 60;
for (int i = 0; i < allDef.size(); i += 1) {
auto it = allDef[i];
if (cursecs >= it->beginsecs && cursecs < it->endsecs) {
if (it->lock == "lock") {
if(QFile::exists("ShowOnce"))
if(lockuntiluserclose){
//this->setFocus();
//this->showNormal();
//this->setFocus();
emit showui(allDef[i]>def,allDef[i]>beginsecs,allDef[i]->endsecs);
break;
if(this->isHidden()){
if(maxscreen==1){
if(this->isHidden() || this->isMaximized()==false)
}else if(fullscreen==1){ this->showFullScreen(); }else{ this->showNormal(); }
this->activateWindow();
//this->setWindowFlag(Qt::WindowStaysOnTopHint);
}else{ this->activateWindow(); }
QString minutenum=QString("%1").arg((it->endsecs - it->beginsecs) / 60);
ui->msgl->setText("Take A Rest "+minutenum +" Minute");
QDateTime dt=QDateTime::currentDateTime();
auto curts=dt.toString("yyyy-MM-ddThh:mm:ss");
ui->resttime->setText(QString("Rest time:")allDef[i]->def" Now:"+curts);
break;
}
if(unlockuntilnextunlock){ emit hideui2(allDef[i]>def,allDef[i]>beginsecs,allDef[i]>endsecs); break; //this>hide(); }else{
//this->setFocus();
//this->showNormal();
//this->setFocus();
emit showui(allDef[i]>def,allDef[i]>beginsecs,allDef[i]->endsecs);
break;
if(this->isHidden()){
if(maxscreen==1)
}else if(fullscreen==1)
{ this->showFullScreen(); }else
{ this->showNormal(); } this->activateWindow();
}else
QString minutenum=QString("%1").arg((it->endsecs - it->beginsecs) / 60);
ui->msgl->setText("Take A Rest "+minutenum +" Minute");
QDateTime dt=QDateTime::currentDateTime();
auto curts=dt.toString("yyyy-MM-ddThh:mm:ss");
ui->resttime->setText(QString("Rest time:")allDef[i]->def" Now:"+curts);
break;
}
}
else if (it->lock == "unlock") {
unlockuntilnextunlock=false;
if(QFile::exists("ShowOnce") || lockuntiluserclose){
QFile::remove("ShowOnce");
lockuntiluserclose=true;
emit showui2(allDef[i]>def,allDef[i]>beginsecs,allDef[i]->endsecs);
break;
if(maxscreen==1){
if(this->isHidden() || this->isMaximized()==false)
}else if(fullscreen==1)
{ this->showFullScreen(); }else
{ this->showNormal(); }this->activateWindow();
ui->msgl->setText("Alt+F4 Close Window For Working");
QDateTime dt=QDateTime::currentDateTime();
auto curts=dt.toString("yyyy-MM-ddThh:mm:ss");
ui->resttime->setText(QString("Now work time:")(allDef[i]->def)" Now:"+curts);
}else{
emit hideui(allDef[i]>def,allDef[i]>beginsecs,allDef[i]->endsecs);
break;
this->hide();
xxminute = "";
//if (this->isHidden()==false)
}
break;
}
}
}
}
}
void MainWindow::closeEvent(QCloseEvent *ce)
{
if(password!=""){
QInputDialog idlg;
idlg.setLabelText("Password");
auto ipass=idlg.getText(this,"Input Close Password","Password:",QLineEdit::Password);
if(ipass!=password)
}
lockuntiluserclose=false;
unlockuntilnextunlock=true;
this->hide();
ce->ignore();
}