why i am getting runtime error " QObject: Cannot create children for a parent that is in a different thread." ?
-
i want to start and stop interrupt at 15 second interval when receive interrupt.
but i am getting runtime error
" QObject: Cannot create children for a parent that is in a different thread.
(Parent is QApplication(0x7efcfb20), parent's thread is QThread(0xc50bf8), current thread is QThread(0x68f006c8) "How to resolve this error ?
#include "MainWindow.h" #include "ui_MainWindow.h" #include <QDebug> #include <QTimer> void gpo_handler() { uint8_t itstatus; MainWindow m; // if( GPO_Activated == 1 ) // { //GPO_Activated = 0; // qDebug()<<"RF write \n"; // printf("RF write \n"); if(m.bStatus == true) { if(m.elapsetime.elapsed()>15000) { BSP_NFCTAG_ConfigIT(0,ST25DV_GPO_ENABLE_MASK | ST25DV_GPO_RFWRITE_MASK );// field is on and off m.bStatus =false; } } ST25_RETRY(BSP_NFCTAG_ReadITSTStatus_Dyn(0, &itstatus )); if( (itstatus & ST25DV_ITSTS_DYN_RFWRITE_MASK) == ST25DV_ITSTS_DYN_RFWRITE_MASK ) { BSP_NFCTAG_ConfigIT(0,0);// field is on and off qDebug()<<"RF write \n"; m.bStatus = true; m.elapsetime.start(); //sleep(15); // BSP_NFCTAG_ConfigIT(0,ST25DV_GPO_ENABLE_MASK | ST25DV_GPO_RFWRITE_MASK );// field is on and off } } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); // const ST25DV_PASSWD st25dv_i2c_password = {.MsbPasswd = 0, .LsbPasswd=0}; bStatus = false; /* Init of the Type Tag 5 component (ST25DV-I2C) */ if(BSP_NFCTAG_Init(0) != NFCTAG_OK); /* Present configuration password */ // BSP_NFCTAG_PresentI2CPassword(0, st25dv_i2c_password ); /* Set GPO Configuration */ BSP_NFCTAG_ConfigIT(0,ST25DV_GPO_ENABLE_MASK | ST25DV_GPO_RFWRITE_MASK );// field is on and off // BSP_NFCTAG_ConfigIT(0,ST25DV_GPO_ENABLE_MASK | ST25DV_GPO_RFWRITE_MASK );// no // BSP_NFCTAG_ConfigIT(0,ST25DV_GPO_ENABLE_MASK | ST25DV_GPO_RFGETMSG_MASK ); // No // BSP_NFCTAG_ConfigIT(0,ST25DV_GPO_ENABLE_MASK | ST25DV_GPO_RFINTERRUPT_MASK ); // No // BSP_NFCTAG_ConfigIT(0,ST25DV_GPO_ENABLE_MASK | ST25DV_GPO_RFPUTMSG_MASK );// NO // BSP_NFCTAG_ConfigIT(0,ST25DV_GPO_ENABLE_MASK | ST25DV_GPO_RFACTIVITY_MASK );// field is on while(ST25DV_GPO_Init() != NFCTAG_OK); while(ST25DV_GPO_interrupt_init(&gpo_handler) != NFCTAG_OK); // ST25DV_GPO_DeInit(); } MainWindow::~MainWindow() { delete ui; }
-
i want to start and stop interrupt at 15 second interval when receive interrupt.
but i am getting runtime error
" QObject: Cannot create children for a parent that is in a different thread.
(Parent is QApplication(0x7efcfb20), parent's thread is QThread(0xc50bf8), current thread is QThread(0x68f006c8) "How to resolve this error ?
#include "MainWindow.h" #include "ui_MainWindow.h" #include <QDebug> #include <QTimer> void gpo_handler() { uint8_t itstatus; MainWindow m; // if( GPO_Activated == 1 ) // { //GPO_Activated = 0; // qDebug()<<"RF write \n"; // printf("RF write \n"); if(m.bStatus == true) { if(m.elapsetime.elapsed()>15000) { BSP_NFCTAG_ConfigIT(0,ST25DV_GPO_ENABLE_MASK | ST25DV_GPO_RFWRITE_MASK );// field is on and off m.bStatus =false; } } ST25_RETRY(BSP_NFCTAG_ReadITSTStatus_Dyn(0, &itstatus )); if( (itstatus & ST25DV_ITSTS_DYN_RFWRITE_MASK) == ST25DV_ITSTS_DYN_RFWRITE_MASK ) { BSP_NFCTAG_ConfigIT(0,0);// field is on and off qDebug()<<"RF write \n"; m.bStatus = true; m.elapsetime.start(); //sleep(15); // BSP_NFCTAG_ConfigIT(0,ST25DV_GPO_ENABLE_MASK | ST25DV_GPO_RFWRITE_MASK );// field is on and off } } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); // const ST25DV_PASSWD st25dv_i2c_password = {.MsbPasswd = 0, .LsbPasswd=0}; bStatus = false; /* Init of the Type Tag 5 component (ST25DV-I2C) */ if(BSP_NFCTAG_Init(0) != NFCTAG_OK); /* Present configuration password */ // BSP_NFCTAG_PresentI2CPassword(0, st25dv_i2c_password ); /* Set GPO Configuration */ BSP_NFCTAG_ConfigIT(0,ST25DV_GPO_ENABLE_MASK | ST25DV_GPO_RFWRITE_MASK );// field is on and off // BSP_NFCTAG_ConfigIT(0,ST25DV_GPO_ENABLE_MASK | ST25DV_GPO_RFWRITE_MASK );// no // BSP_NFCTAG_ConfigIT(0,ST25DV_GPO_ENABLE_MASK | ST25DV_GPO_RFGETMSG_MASK ); // No // BSP_NFCTAG_ConfigIT(0,ST25DV_GPO_ENABLE_MASK | ST25DV_GPO_RFINTERRUPT_MASK ); // No // BSP_NFCTAG_ConfigIT(0,ST25DV_GPO_ENABLE_MASK | ST25DV_GPO_RFPUTMSG_MASK );// NO // BSP_NFCTAG_ConfigIT(0,ST25DV_GPO_ENABLE_MASK | ST25DV_GPO_RFACTIVITY_MASK );// field is on while(ST25DV_GPO_Init() != NFCTAG_OK); while(ST25DV_GPO_interrupt_init(&gpo_handler) != NFCTAG_OK); // ST25DV_GPO_DeInit(); } MainWindow::~MainWindow() { delete ui; }
@Qt-embedded-developer said in why i am getting runtime error " QObject: Cannot create children for a parent that is in a different thread." ?:
MainWindow m;
Why do you create an instance of MainWindow in your gpo_handler()?!
-
@Qt-embedded-developer said in why i am getting runtime error " QObject: Cannot create children for a parent that is in a different thread." ?:
MainWindow m;
Why do you create an instance of MainWindow in your gpo_handler()?!
@jsulm to start and stop interrupt at 15 second while receive interrupt.
-
@jsulm to start and stop interrupt at 15 second while receive interrupt.
@Qt-embedded-developer said in why i am getting runtime error " QObject: Cannot create children for a parent that is in a different thread." ?:
to start and stop interrupt at 15 second while receive interrupt.
You should contact the already existing MainWindow instance instead of creating a new MainWindow every time gpo_handler() is called...
-
@Qt-embedded-developer said in why i am getting runtime error " QObject: Cannot create children for a parent that is in a different thread." ?:
to start and stop interrupt at 15 second while receive interrupt.
You should contact the already existing MainWindow instance instead of creating a new MainWindow every time gpo_handler() is called...
@jsulm How to create MainWindow instance in MainWindow class ? Please provide example
-
@jsulm How to create MainWindow instance in MainWindow class ? Please provide example
@Qt-embedded-developer You create your MainWindow instance in main() already, right?
I suggest to do this:MainWindow* mainWindowInstance{nullptr}; void gpo_handler() { uint8_t itstatus; if (!mainWindowInstance) return; if(mainWindowInstance.bStatus == true) ... } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { mainWindowInstance = this;
-
@Qt-embedded-developer You create your MainWindow instance in main() already, right?
I suggest to do this:MainWindow* mainWindowInstance{nullptr}; void gpo_handler() { uint8_t itstatus; if (!mainWindowInstance) return; if(mainWindowInstance.bStatus == true) ... } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { mainWindowInstance = this;
@jsulm said in why i am getting runtime error " QObject: Cannot create children for a parent that is in a different thread." ?:
mainWindowInstance.bStatus
i got below error while i write above code
error: 'nullptr' was not declared in this scope
MainWindow* mainWindowInstance{nullptr};
^ -
@jsulm said in why i am getting runtime error " QObject: Cannot create children for a parent that is in a different thread." ?:
mainWindowInstance.bStatus
i got below error while i write above code
error: 'nullptr' was not declared in this scope
MainWindow* mainWindowInstance{nullptr};
^@Qt-embedded-developer What compiler do you use?!
C++11 compiler should know what nullptr is, but you also can simply use 0.