Question: hi all i want to update ui from a non member function. Any help other than passing 'this' pointer as my non member is a callback from library.

Below is my code :

mainwindow.cpp

```
static void callback(QString result) 
{
ui->textBrowser->append(result);
}

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::on_pushButton_clicked()
{
int a=1,b=2;
QLibrary myLib("myaddlib");
myLib.load();
add = (myadd)myLib.resolve("add_function");
add(callback, a, b);
}

```

So all I need is I should be able to append data to UI from my non member callback. Please help me.

EDIT: i am not permitted to modify my callback

EDIT based on comment: `callback` will be called in a different thread, so calling a widget method from there gives error `'cannot send events to objects owned by a different thread'`

Answer: 
Going by your comment 

> 
> "i tried to create global pointer Ui::MainWindow \*myui and assigned
>  myui to ui in the constructor but it throws me following error :
>  'cannot send events to objects owned by a different thread'."
> 
> 
> 

Problem is, your `callback` gets called in the wrong thread. Here's one solution:

1. Create global pointer to the actual main window instance, let's call it `MainWindow *mainWinInstance;`. Also be careful that the main window instance will live longer than the library/thread for which the callback is for, or use `QPointer` if there's risk that `callback` gets called even after the main window was destructed.
2. Add following slot method to `MainWindow`:

```
MainWindow::appendText(const QString &text) { // use const ref for efficiency
    ui->textBrowser->append(result);
}

```
3. Change your `callback` to invoke that method using [`QMetaObject::invokeMethod`](http://qt-project.org/doc/qt-5/qmetaobject.html#invokeMethod-3) using queued connection type:

```
static void callback(QString result) {
    bool r = QMetaObject::invokeMethod(mainWinInstance, 
                                       "appendText", 
                                       Qt::QueuedConnection,
                                       Q_ARG(QString, result));
    Q_ASSERT(r); // should only fail if there's a mistake in above code
}

```

Using `Qt::QueuedConnection` is impotant. It will place the method invocation in the event queue of the correct thread of the target object and return immediately. The event loop of the target thread will then do the actual call.
None of the things worked for me which were mentioned here. 
Solved it by creating a dummy Qobject which has a public function to send signal to mainwindow. Create an instance of this dummy qobject and call the public function inside my callback.

PS: I have a limitation not to modify my callback hence the above solution.