show your code.
It seems 'LCD' is null.
show your code.
It seems 'LCD' is null.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Start a new thread and run the worker_thread()
Qt Code:
settings_agent.moveToThread(settingsFileUpdaterThread); settingsFileUpdaterThread->start();To copy to clipboard, switch view to plain text mode
Qt Code:
void SettingsFileRetrievalAgent::worker_thread() { while(1) status = updateSettingsIfPossible(); if (status == RETURN_SUCCESS_CACHE_UPDATED) { emit updatedSettingsNotification(); //segfault } for( int count = 0; count < 2; ++count ) sleep( 1 ); } }To copy to clipboard, switch view to plain text mode
I have other threads that are just about identical and they don't seem to have a problem when emitting a signal.
Right.
Where did you initialize 'LCD'?
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Qt Code:
ui(new Ui::MainWindow) { ui->setupUi(this); }To copy to clipboard, switch view to plain text mode
Qt Code:
void MainWindow::startup() // Get pointer to layout manager for main window // Add LCD screen to the main window layout at specified position LCD = new(IPR5000_LCD)(this); LCD->setGeometry(430,50,320,240); LCD->setParent(this); layout->addWidget(LCD); }To copy to clipboard, switch view to plain text mode
does this initialization happen before you start settingsFileUpdaterThread ?
If so, what exactly "restaring()" does?
Sound like a place where all kind of mischief can happen, if "restarting()" is re-spawning threads or similar thread related stuff - if this is the case - care has to be taken that things are all correctly terminated and initialized.
If you comment out all the content of "restarting()" does it still crash (the same way)?
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Qt Code:
void MainWindow::startup() // Get pointer to layout manager for main window // Add LCD screen to the main window layout at specified position LCD = new(IPR5000_LCD)(this); LCD->setGeometry(430,50,320,240); LCD->setParent(this); layout->addWidget(LCD); KeyManagementAgent key_management_agent; SettingsFileRetrievalAgent settings_agent( key_management_agent ); connect(&settings_agent, SIGNAL(updateSettingsNotification()), LCD, SLOT(restarting())); // move it to its own thread and do stuff with it. settings_agent.moveToThread(settingsFileUpdaterThread); settingsFileUpdaterThread->start(); }To copy to clipboard, switch view to plain text mode
Qt Code:
void IPR5000_LCD::restarting() { ui->stackedWidget->setCurrentIndex(2); }To copy to clipboard, switch view to plain text mode
Like I said previously I do this sort of thing other places without problems so I don't see any reason there would be a problem with the 'LCD', it just happens to be this thread that is giving me issues.
Commenting out the code in the restarting() method still results in a segfault. I tried printing a simple debug message and it still crashes. I don't think it's a problem with the LCD class. The LCD slot is never called because the signal is never emitted, that's how I know it cant be the LCD.
Edit: It will loop about 5-8 times before it throws a segfault.
I really appreciate the help.
Last edited by Chris@Link; 3rd July 2012 at 17:59.
1. Is 'key_management_agent' a parent for 'settings_agent' or just a parameter?
2. settings_agent is a stack variable, which dies at the end of the constructor. I would expect moveToThread() to have a problem with that - try allocating it on the heap.
This would also explain this==NULL.
1.LCD was a likely candidate - since I don't know your code I wanted to rule it out.Like I said previously I do this sort of thing other places without problems so I don't see any reason there would be a problem with the 'LCD', it just happens to be this thread that is giving me issues.
2.I fail to see the relevance of the claim that something worked somewhere else since obviously its not *exactly* the same, and secondly, obviously it doesn't work here - so it helps little that it does somewhere else.
Specially when threads are in question - since alone different hardware (same software) may produce different results, or bring bugs to the surface on one system that are not see on another.
For your own good - stop thinking "this has to work" if it doesn't - rather "I must be doing something wrong if it doesn't work".
By the way, the code as you posted it, really requires no threads.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Upon further investigation the settings_agent and the key_management_agent was being destroyed after we finished the startup function. I don't know how I managed to overlook that but I did.
I understand, I was extremely frustrated and I overlooked the fact that the stack variable was being destroyed.
Thanks for the help.
Bookmarks