You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Sunday, August 23rd 2009, 7:22pm

QThread and the hell

So... i'm doing a Thread through Qthread

before Exec(), i need to do some previous IP TCP checks to some locations. I use my Run() function (that ends with the exec()) to do those previous checks. The problem is that i want to give the user the chance to go one way or another depending on the results of those checks.

So, inside my Run function i tried to call a QMessageBox, but the program crashes every time it has to open something related to QWidget from a QThread function related.

Any ideas why? Any ideas to know how to do what i'd like?

thanks


Edit: code

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void doitThread::run()  {
 //Try to connect to someone first
socket = new QTcpSocket();
 int i = 0;
 while (socket->state()!=QAbstractSocket::ConnectedState && i<clients->count()){
   fb->lineEdit("Prova de connexió amb "+clients->at(i));
   socket->connectToHost(QHostAddress(clients->at(i)), 6999);
   socket->waitForConnected(1000);
   i++;
 }
 if (socket->state()!=QAbstractSocket::ConnectedState){  //id like to let the user decide what to do if i haven't been able to connect to anyone
  bool decide=false;
   askServer * ask = new askServer(parent, &decide);   //This is similar to a message box class, click ok or cancel, and the result is saved in the bool parametre

   ask.exec();
 if (decide==false){
   socket->close();
   this->exit(0);   
}
 } 
          exec(); 
 }

This post has been edited 5 times, last edit by "neosengla" (Aug 23rd 2009, 7:33pm)


2

Monday, August 24th 2009, 5:38pm

Perhaps you can use the signal and slots to do it.

you can emit a signal (such as, emit showMessage("message");),and in the widget class ,connect this signal to your slot.

3

Tuesday, August 25th 2009, 1:12am

whoa thanks ill try that!