Blocking code crashes after code block finishes
joshorenberg opened this issue · comments
no clue without seeing actual code, or a minimal code that crashes
Here 'tis, a little stripped for the relevant parts only. The situation I've been testing is with a multimap with only one key value pair and the program crashes when exiting the inner code block. Thanks!
void Program::sendEmails()
{
QMultiMap<QString,BackupJob>::const_iterator iterator = emailAddressMultiMap.constBegin();
while (iterator != emailAddressMultiMap.constEnd())
{
messageString += ... //construct the string here
SimpleMail::Sender sender("smtp.***.com", 465, SimpleMail::Sender::SslConnection);
sender.setUser("address@***.com");
sender.setPassword("password");
SimpleMail::MimeMessage message;
message.setSender(SimpleMail::EmailAddress("from@from.com", "Program"));
message.addTo(SimpleMail::EmailAddress(iterator.key()));
message.setSubject("Email");
SimpleMail::MimeText text;
text.setText(messageString);
message.addPart(&text);
sender.sendMail(message); // Blocks untill mail is delivered or errored
//qDebug() << sender.responseText();
sender.quit();
QString emailAddress = iterator.key();
while (iterator != emailAddressMultiMap.constEnd() && iterator.key() == emailAddress)
++iterator;
}
}
addPart() takes ownership of part so it will crash as it get's deleted twice.
How to remedy? Also that code was borrowed from example 1 and the main page example, would be nice to update for the newbies out there (and maybe not so newbies...) Or is it a bug? Thanks for the quick response.
I found a workaround for the error... I offloaded the email sending code to a worker thread (which is what I wanted in the first place) and everything is working now, no more crashes. Weird...