c++ - C2065: "ui" : undeclared identifier -


i'm writting first program in qt designer, , have problem changing qlineedit text nothing. want use operation detached thread, can continue working in part of program without waiting end of sleep(5000) function. when want compile code i'm getting 3 errors:

c2065: "ui" : undeclared identifier

c2227: left "->autowyl_textpotwierdzenie" must pointing type class/struct/union/generic

c2227: left "->settext" must pointing type class/struct/union/generic

could me errors? in advance.

here problematic part of code:


    {...            void autowyl_potwierdzenie_reset();         std::thread reset(autowyl_potwierdzenie_reset);         reset.detach();     }      void autowyl_potwierdzenie_reset()     {         sleep(5000);         ui->autowyl_textpotwierdzenie->settext(""); //3 errors     } 

i think creating thread method of class containing ui (which pointer ui::thewidgetyoudesignedinqtdesigner). on other hand, function thread runs out of class, can't reach ui.

i suggest passing ui parameter, or, better, passing qlineedit:

// ... std::thread reset(autowyl_potwierdzenie_reset, ui-> autowyl_textpotwierdzenie); // ...  void autowyl_potwierdzenie_reset(qlineedit* lineedit) {     sleep(5000);     lineedit->settext(""); } 

if autowyl_potwierdzenie_reset never used again, can use lambda function instead (increasing readability of code):

std::thread reset([ui]() {   sleep(5000);   ui->autowyl_textpotwierdzenie->settext(""); }); reset.detach(); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -