No Matching Function for call to run int!



  • Bros!
    I am doing socket programming in Qt. Actually i have already programmed the console version and converting it to GUI! At certain point i realized that on of the functions iam calling is a blocking one and on calling it programs goes stuck. To resolve the issue i applied thread when i came across this thing "No matching function for call to run int"
    My Piece of code is:
    @void FtpWindow::throwConnection()
    {
    char command[MINIBUF];
    int ret;
    int socketfd;
    int clientSocketfd;
    char buf[BUFF];
    int port = server_port;
    socketfd = getSocket(&port);
    ::listen(socketfd, 20);
    struct sockaddr_in client_in;
    socklen_t len = sizeof(struct sockaddr_in);

    //accept(socketfd, (struct sockaddr *)&client_in, &len))
    QFuture<int> future = QtConcurrent::run(::accept(socketfd, (struct sockaddr *)&client_in, &len));
    
    clientSocketfd = future.result();
    

    // {
    // QMessageBox::information(this, tr("FTP"),tr("Accept error"));
    // }
    //// else
    // QMessageBox::information(this, tr("FTP"),tr("Accepted successfully!"));

    }
    @

    the main reason to apply separate thread was due to the blocking structure of:
    @::accept(socketfd, (struct sockaddr *)&client_in, &len)@ function.

    I've googled enough but did not comeup with something helpful in qt's context. Any bro has idea plz help providing that i have already configured all headers/slots/signals. If there is any other way to achieve this without using thread that will be equally appreciated.
    Regards.



  • Hi samiansari,

    I have never used QtConcurrent, but from what I read in the docs, I expect the call to be:

    @
    QFuture<int> future = QtConcurrent::run(&accept, socketfd, (struct sockaddr *)&client_in, &len);
    @

    Your stuff would call the function and pass the return value to QtConcurrent::run() which makes no sense. This one passes a function pointer and the parameters.

    But it will stay blocking, untill you expect the result in the same function. And if not, you will have crashed when accessing the variables, as they are invalid after FtpWindow::throwConnection.

    My suggestion would be, create a real thread with QThread and do the work there. Introduce signal/slot for the results. You can have a look at: "peppes wiki article ":http://developer.qt.nokia.com/wiki/ThreadsEventsQObjects



  • There's still ways to solve this with QtConcurrent, but you need to use QFutureWatcher, and handle the data nicely. When using QFuture and QFutureWatcher, you still have the signals and slots, but no longer the management over the threads.



  • Geroif and Franzk I appreciate your concern, I really do.
    Geroif: The good thing is after applying the rectification you have pointed out for argument passing, my program compiled without any error :) but the bad think is its still working in blocking mode destroying my very purpose of exciting that function on separate thread. I followed the documentation and your absolutely right about using QThread. But the thing is iam not that much vigilant to grasp it by myself since the QThread class is to be built in header file (as far as ive observed) this will require my Function implementation inside void Run() to have global variables so that i can pass result through to my main program. Can you plz guide me in the right direction! Regards.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.