Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Problem : MySQL server has gone away QMYSQL: Unable to execute query

$
0
0
Hello, I ask this message because I have a problem with QMySql. I create a local database consists of two tables (inbox, outbox), I use smsd daemon to be able to send messages via Mobile module. I use a thread to regularly go retrieve incoming messages (inbox table) and send messages that I insert in the other table (outbox). I develop on OpenSuse 12.2 and Qt 4.8.1 operating system. I use QMYSQL driver and my problem is that I can only insert in the outbox table once. I let you see the code: My first window opens the database:     db=new QSqlDatabase(QSqlDatabase::addDatabase("QMYSQL","qmysql"));       db->setUserName("root");                        //-Connexion à la base de donnée locale       db->setDatabaseName("smsd");       db->setHostName("127.0.0.1");       db->setPort(3306);       if(!db->open())       {           cout<<"Connexion à la base de donnée locale échouée.";       }       else       {           this->sms = new C_Gsm(db);           cout<<"Connexion à la base de donnée locale réussie.";           sms->LancerThread();                            //-Lancement du thread du gsm           App = new C_Application_Chauffeur(sms);           this->identifiant = App->DemanderPlanning();           ui->label_5->setText(identifiant);              //-Affichage de l'identifiant de connexion OpenSuse       }   My method that fits into the outbox table:      QSqlQuery query(*db);           bool ok=0;           short nbsms=(message.length()/160)+1,i=0;           if(nbsms==1)           {               QFile file("test.txt");               file.open(QIODevice::Append | QIODevice::Text);               QTextStream flux(&file);               flux.setCodec("UTF-8");                     ok=query.exec("insert into outbox (number,text) values('"+numero+"','"+message.toUtf8()+"');");                     flux.operator <<(query.lastError().text()+"\n");               file.close();           }           else           {               do               {                   string mess=message.toStdString().substr(i*160,160);                   ostringstream oss;                   oss<<nbsms<<"-"<<i+1;                   mess.replace(4,3,oss.str());                   query.exec("insert into outbox (number,text) values('"+numero+"','"+message.toUtf8()+"');");                   i++;               }while((i+1)<=nbsms);           }           message.clear();       }   As you can see, I create a text file that shows me the sql error log, the error message is: MySQL server has gone away QMYSQL: Unable to execute query I do not understand really, I did some research on the internet but I have not found… The thing is that I can fit into my table again, but next time, the error message! Thank you in advance and sorry for my bad English.

Viewing all articles
Browse latest Browse all 13965

Trending Articles