<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Send a text to textEdit from a non qt cpp file]]></title><description><![CDATA[<p dir="auto">Hi, I know there is lot of topic about this but I cant find my answer, so sorry about that<br />
I have this<br />
in worker.h header</p>
<pre><code class="language-c++">#ifndef Worker_H
#define Worker_H

#define RTN_OK		0
#define RTN_USAGE	1
#define RTN_ERROR	13

#include &lt;stdio.h&gt;
#include &lt;Windows.h&gt;


#define DEBUG_NTBUFFER

bool GetOSInfo();

// Escalate Privilege to SYSTEM level
bool SetPrivilege(HANDLE hToken, LPCTSTR Privilege, BOOL bEnablePrivilege);
int EscalatePrivilege();

bool CreateRemoteThread_Type1(LPCSTR ID, HANDLE hProcess);

#endif
</code></pre>
<p dir="auto">I have two cpp file for <code>SetPrivilege</code> and <code>CreateRemoteThread</code> that include worker.h</p>
<p dir="auto">Im including worker.h in my mainw too and useing it, I want to know how can I get some text from <code>SetPrivilege</code> and <code>CreateRemoteThread</code> and show it in mainw ui</p>
<p dir="auto">sorry if I explain it so bad, But im be grateful if anyone help me</p>
]]></description><link>https://forum.qt.io/topic/122410/send-a-text-to-textedit-from-a-non-qt-cpp-file</link><generator>RSS for Node</generator><lastBuildDate>Sun, 05 Apr 2026 18:27:36 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/122410.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 06 Jan 2021 12:26:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Send a text to textEdit from a non qt cpp file on Thu, 07 Jan 2021 06:13:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
Hi, I worked with it a little more and I come up with this codes</p>
<p dir="auto"><code>worker.h</code></p>
<pre><code class="language-c++">class Worker : public QObject
{
	Q_OBJECT

public:
	bool GetOSInfo();
	bool SetPrivilege(HANDLE hToken, LPCTSTR Privilege, BOOL bEnablePrivilege);
	void DisplayError(LPCSTR szAPI);
	int EscalatePrivilege();
	bool CreateRemoteThread_Type1(LPCSTR ID, HANDLE hProcess);

signals:
	void updateUI(const int error, const QString text, const QString value);

};
</code></pre>
<p dir="auto"><code>CreateRemoteThread.cpp</code></p>
<pre><code class="language-c++">bool Worker::CreateRemoteThread_Type1(LPCSTR ID, HANDLE hProcess) {
//some code
	emit updateUI(0, "text", Null);
}
</code></pre>
<p dir="auto"><code>mainwindow.h</code></p>
<pre><code class="language-c++">private slots:
    void Reciver(const int error, const QString text, const QString value);
</code></pre>
<p dir="auto">and <code>mainwindow.cpp</code></p>
<pre><code class="language-cpp">Worker worker; //global

Mainwindow::Mainwindow(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);
		
	QObject::connect(&amp;worker, &amp;Worker::updateUI, this, &amp;mainwindow::Reciver);
}

//some code

void mainwindow::Reciver(const int error, const QString text, const QString value)
{
	ui.textEdit-&gt;append(text);
}
</code></pre>
<p dir="auto">its working and slot Trigger when signal fired<br />
I only want to know there is any better way then declare Worker globally in mainwindow? (i declare it globally because I need it some other function other then main)<br />
and one other thing, after all this code ideal?</p>
<p dir="auto">thanks for all your helps and sorry for bothering you so many times</p>
]]></description><link>https://forum.qt.io/post/636283</link><guid isPermaLink="true">https://forum.qt.io/post/636283</guid><dc:creator><![CDATA[saeid0034]]></dc:creator><pubDate>Thu, 07 Jan 2021 06:13:51 GMT</pubDate></item><item><title><![CDATA[Reply to Send a text to textEdit from a non qt cpp file on Wed, 06 Jan 2021 20:20:35 GMT]]></title><description><![CDATA[<p dir="auto">one other thing<br />
know I can access ui from all c++ file I declared in header<br />
its bad? and why?</p>
]]></description><link>https://forum.qt.io/post/636266</link><guid isPermaLink="true">https://forum.qt.io/post/636266</guid><dc:creator><![CDATA[saeid0034]]></dc:creator><pubDate>Wed, 06 Jan 2021 20:20:35 GMT</pubDate></item><item><title><![CDATA[Reply to Send a text to textEdit from a non qt cpp file on Wed, 06 Jan 2021 19:43:12 GMT]]></title><description><![CDATA[<p dir="auto">I manage to fix it wait add in function deceleration from worker.h to mainwindow.h<br />
know I can send signal and receive it<br />
I'm still don't know if its a good way to do this...</p>
]]></description><link>https://forum.qt.io/post/636252</link><guid isPermaLink="true">https://forum.qt.io/post/636252</guid><dc:creator><![CDATA[saeid0034]]></dc:creator><pubDate>Wed, 06 Jan 2021 19:43:12 GMT</pubDate></item><item><title><![CDATA[Reply to Send a text to textEdit from a non qt cpp file on Wed, 06 Jan 2021 19:29:35 GMT]]></title><description><![CDATA[<p dir="auto">send out your text via standard output std::cout in your cpp code and catch it in Qt code.<br />
<a href="https://forum.qt.io/topic/80024/how-to-redirect-output-of-stdout-to-gui-qtextedit-shell-from-one-process-to-another-process/2">https://forum.qt.io/topic/80024/how-to-redirect-output-of-stdout-to-gui-qtextedit-shell-from-one-process-to-another-process/2</a></p>
]]></description><link>https://forum.qt.io/post/636245</link><guid isPermaLink="true">https://forum.qt.io/post/636245</guid><dc:creator><![CDATA[JoeCFD]]></dc:creator><pubDate>Wed, 06 Jan 2021 19:29:35 GMT</pubDate></item><item><title><![CDATA[Reply to Send a text to textEdit from a non qt cpp file on Wed, 06 Jan 2021 18:11:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/saeid0034">@<bdi>saeid0034</bdi></a> said in <a href="/post/636209">Send a text to textEdit from a non qt cpp file</a>:</p>
<blockquote>
<p dir="auto">you think if I include all my needed function from CreateRemoteThread_Type1 and SetPrivilege  in my mainwindow code its okay?</p>
</blockquote>
<p dir="auto">This is not ideal!  You <em>really</em> want to keep separation between a Qt main window/program and some piece of Windows-specific code to do goodness what.  Try to make a self-contained class out of what you have with this code.  But this is a general programming issue.</p>
]]></description><link>https://forum.qt.io/post/636215</link><guid isPermaLink="true">https://forum.qt.io/post/636215</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 06 Jan 2021 18:11:10 GMT</pubDate></item><item><title><![CDATA[Reply to Send a text to textEdit from a non qt cpp file on Wed, 06 Jan 2021 16:58:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/636203">Send a text to textEdit from a non qt cpp file</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/saeid0034">@<bdi>saeid0034</bdi></a><br />
I knew you were going to ask that next! :)  I'm afraid, that's your problem!  I don't know enough about how your <code>CreateRemoteThread_c</code> code/object(s) fit together with your main window code.  Do you create <code>CreateRemoteThread_c</code> instances more than once?  If there really is only one you could use a singleton pattern.  Or, main window can create it, I don't know what your non-class function <code>CreateRemoteThread_Type1</code> is about, why you needed that.</p>
<p dir="auto">Only you know how your code relates.  Whatever, the instance that does the <code>emit</code> of the signal <em>must</em> be the same instance as main window specifies in its <code>connect()</code> statement, that is what is vital.</p>
</blockquote>
<p dir="auto">thank you for all your help and Sorry for bother you so much<br />
at the end I think my best solution is change my code, one last question😅<br />
you think if I include all my needed function from <code>CreateRemoteThread_Type1</code> and <code>SetPrivilege</code>  in my mainwindow code its okay?</p>
]]></description><link>https://forum.qt.io/post/636209</link><guid isPermaLink="true">https://forum.qt.io/post/636209</guid><dc:creator><![CDATA[saeid0034]]></dc:creator><pubDate>Wed, 06 Jan 2021 16:58:19 GMT</pubDate></item><item><title><![CDATA[Reply to Send a text to textEdit from a non qt cpp file on Wed, 06 Jan 2021 16:31:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/saeid0034">@<bdi>saeid0034</bdi></a><br />
I knew you were going to ask that next! :)  I'm afraid, that's your problem!  I don't know enough about how your <code>CreateRemoteThread_c</code> code/object(s) fit together with your main window code.  Do you create <code>CreateRemoteThread_c</code> instances more than once?  If there really is only one you could use a singleton pattern.  Or, main window can create it, I don't know what your non-class function <code>CreateRemoteThread_Type1</code> is about, why you needed that.</p>
<p dir="auto">Only you know how your code relates.  Whatever, the instance that does the <code>emit</code> of the signal <em>must</em> be the same instance as main window specifies in its <code>connect()</code> statement, that is what is vital.</p>
]]></description><link>https://forum.qt.io/post/636203</link><guid isPermaLink="true">https://forum.qt.io/post/636203</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 06 Jan 2021 16:31:35 GMT</pubDate></item><item><title><![CDATA[Reply to Send a text to textEdit from a non qt cpp file on Wed, 06 Jan 2021 16:09:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
oh, yes you right, but one question how can I use one object for both <code>mainwindow</code> and <code>CreateRemoteThread_Type1</code>?</p>
]]></description><link>https://forum.qt.io/post/636197</link><guid isPermaLink="true">https://forum.qt.io/post/636197</guid><dc:creator><![CDATA[saeid0034]]></dc:creator><pubDate>Wed, 06 Jan 2021 16:09:05 GMT</pubDate></item><item><title><![CDATA[Reply to Send a text to textEdit from a non qt cpp file on Wed, 06 Jan 2021 15:52:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/saeid0034">@<bdi>saeid0034</bdi></a><br />
Look, I'm not sure [actually, I am sure], but: in <code>CreateRemoteThread_Type1</code> you have a <code>CreateRemoteThread_c Sender;</code> local variable which is the signal sender.  Meanwhile in the <code>connect()</code> you have a new <code>CreateRemoteThread_c</code> object, <code>MsgSender</code>.  What is going on here?  The connection must be from the object which sends the signal, and I think you have two completely separate objects here??</p>
]]></description><link>https://forum.qt.io/post/636190</link><guid isPermaLink="true">https://forum.qt.io/post/636190</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 06 Jan 2021 15:52:48 GMT</pubDate></item><item><title><![CDATA[Reply to Send a text to textEdit from a non qt cpp file on Wed, 06 Jan 2021 15:24:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/636179">Send a text to textEdit from a non qt cpp file</a>:</p>
<blockquote>
<p dir="auto">Glancing through your code, it looks reasonable.</p>
</blockquote>
<p dir="auto">as you said I check the code with <code>qDebug()</code><br />
<code>SendMSG</code> function called but seems like signal doesn't emit<br />
I dont know what is my problem<br />
edit<br />
yes, I tested connect with lambda and tried to show a massage when signal received, but nothing happened.</p>
]]></description><link>https://forum.qt.io/post/636182</link><guid isPermaLink="true">https://forum.qt.io/post/636182</guid><dc:creator><![CDATA[saeid0034]]></dc:creator><pubDate>Wed, 06 Jan 2021 15:24:40 GMT</pubDate></item><item><title><![CDATA[Reply to Send a text to textEdit from a non qt cpp file on Wed, 06 Jan 2021 14:44:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/saeid0034">@<bdi>saeid0034</bdi></a><br />
Glancing through your code, it looks reasonable.  As ever, while developing use <code>qDebug()</code> messages to verify your signal is being emitted, received etc.</p>
]]></description><link>https://forum.qt.io/post/636179</link><guid isPermaLink="true">https://forum.qt.io/post/636179</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 06 Jan 2021 14:44:05 GMT</pubDate></item><item><title><![CDATA[Reply to Send a text to textEdit from a non qt cpp file on Wed, 06 Jan 2021 14:26:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
I know I cant explain my problem right and im sorry about that<br />
the only thing I want is send a text from a cpp file that include my codes to mainwindow ui<br />
I tried this, but its wont work<br />
in <code>CreateRemoteThread_Type1</code> header</p>
<pre><code class="language-c++">#pragma once

#include &lt;QObject&gt;

class CreateRemoteThread_c: public QObject
{
	Q_OBJECT

public:
	CreateRemoteThread_c(QObject *parent = Q_NULLPTR);
	void SendMSG(int error, QString str_2, QString str);

signals:
	void updateUI(int error, QString str_2, QString str);
};
</code></pre>
<p dir="auto">in in <code>CreateRemoteThread_Type1</code> cpp file</p>
<pre><code class="language-c++">#include "Injector.h"
#include "CreateRemoteThread_Type1.h"

CreateRemoteThread_c::CreateRemoteThread_c(QObject *parent)
	: QObject(parent)
{
}

void CreateRemoteThread_c::SendMSG(int error, QString str_2, QString str)
{
	emit updateUI(error, str_2, str);
}

bool CreateRemoteThread_Type1(LPCSTR ID, HANDLE hProcess)
{
	CreateRemoteThread_c Sender;
	Sender.SendMSG(0, "string", "string 2");

}
</code></pre>
<p dir="auto">and after that I include <code>CreateRemoteThread_Type1.h</code> in my mainwindow header<br />
also Im created a slot in mainwindow header and created it in cpp file too</p>
<pre><code class="language-c++">private slots:
    void AppendToTextEdit(int error, QString str_2, QString str);
</code></pre>
<p dir="auto">then connect <code>updateUI</code> signal to <code>AppendToTextEdit</code> slot in <code>mainwindow::mainwindow(QWidget *parent)</code> in my mainwindow.cpp</p>
<pre><code class="language-c++">CreateRemoteThread_c* MsgSender = new CreateRemoteThread_c;

	QObject::connect(MsgSender, &amp;CreateRemoteThread_c::updateUI, this, &amp;mainwindow::AppendToTextEdit);
</code></pre>
<p dir="auto">but slot never called<br />
sorry for long text, can you please tell me what is my problem?</p>
]]></description><link>https://forum.qt.io/post/636177</link><guid isPermaLink="true">https://forum.qt.io/post/636177</guid><dc:creator><![CDATA[saeid0034]]></dc:creator><pubDate>Wed, 06 Jan 2021 14:26:49 GMT</pubDate></item><item><title><![CDATA[Reply to Send a text to textEdit from a non qt cpp file on Wed, 06 Jan 2021 13:21:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/saeid0034">@<bdi>saeid0034</bdi></a><br />
There are no files here in code.  Do you mean send something from these <code>.cpp</code> files??</p>
<p dir="auto">Would you be prepared to include <code>QObject</code> stuff here so that you can send signals back to your Qt code?</p>
<p dir="auto">It's hard to say, maybe somebody else knows what you are asking because I am struggling.</p>
<p dir="auto">As I said, this code has nothing at all to do with Qt, and I have no idea how or why you're using it your Qt app....</p>
]]></description><link>https://forum.qt.io/post/636165</link><guid isPermaLink="true">https://forum.qt.io/post/636165</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 06 Jan 2021 13:21:31 GMT</pubDate></item><item><title><![CDATA[Reply to Send a text to textEdit from a non qt cpp file on Wed, 06 Jan 2021 12:41:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
sorry my bad, about CreateRemoteThread i suppose to Write <code>CreateRemoteThread_Type1</code> . it name of a function in a cpp file, I use it for some things<br />
alse here is code for SetPrivilege</p>
<pre><code class="language-c++">#include "injector.h"

bool SetPrivilege(HANDLE hToken, LPCTSTR Privilege, BOOL bEnablePrivilege) {

	TOKEN_PRIVILEGES tp;
	LUID luid;
	TOKEN_PRIVILEGES tpPrevious;
	DWORD cbPrevious = sizeof(TOKEN_PRIVILEGES);

	if (!LookupPrivilegeValue(NULL, Privilege, &amp;luid)) return false;

	// First pass. get current privilege settings
	tp.PrivilegeCount = 1;
	tp.Privileges[0].Luid = luid;
	tp.Privileges[0].Attributes = 0;

	AdjustTokenPrivileges(
		hToken,
		FALSE,
		&amp;tp,
		sizeof(TOKEN_PRIVILEGES),
		&amp;tpPrevious,
		&amp;cbPrevious);

	if (GetLastError() != ERROR_SUCCESS) return false;

	// second pass. set privileges based on previous settings

	tpPrevious.PrivilegeCount = 1;
	tpPrevious.Privileges[0].Luid = luid;

	if (bEnablePrivilege) {
		tpPrevious.Privileges[0].Attributes |= (SE_PRIVILEGE_ENABLED);
	}
	else {
		tpPrevious.Privileges[0].Attributes ^= (SE_PRIVILEGE_ENABLED &amp; tpPrevious.Privileges[0].Attributes);
	}

	AdjustTokenPrivileges(
		hToken,
		FALSE,
		&amp;tpPrevious,
		cbPrevious,
		NULL,
		NULL
	);


	if (GetLastError() != ERROR_SUCCESS) return false;

	return true;
}


void DisplayError(LPCSTR szAPI) {

	LPTSTR MessageBuffer;
	DWORD dwBufferLength;

	fprintf(stderr, "%s() error!\n", szAPI);

	if (dwBufferLength = FormatMessage(
		FORMAT_MESSAGE_ALLOCATE_BUFFER |
		FORMAT_MESSAGE_FROM_SYSTEM,
		NULL,
		GetLastError(),
		GetSystemDefaultLangID(),
		(LPTSTR)&amp;MessageBuffer,
		0,
		NULL
	)) {

		DWORD dwBytesWritten;

		// Output message string on stterr
		WriteFile(
			GetStdHandle(STD_ERROR_HANDLE),
			MessageBuffer,
			dwBufferLength,
			&amp;dwBytesWritten,
			NULL
		);

		// Free the buffer alllocated by the system
		LocalFree(MessageBuffer);
	}

}

int EscalatePrivilege() {

	HANDLE hToken;
	int dwRetVal = RTN_OK;

	if (!OpenThreadToken(GetCurrentThread(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, FALSE, &amp;hToken)) {

		if (GetLastError() == ERROR_NO_TOKEN) {
			if (!ImpersonateSelf(SecurityImpersonation)) return RTN_ERROR;

			if (!OpenThreadToken(GetCurrentThread(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, FALSE, &amp;hToken)) {
				DisplayError("OpenThreadToken");
				return RTN_ERROR;
			}

		}
		else {
			return RTN_ERROR;
		}
	}

	// Enable SetPrivilege()

	if (!SetPrivilege(hToken, SE_DEBUG_NAME, TRUE)) {

		DisplayError("Set Privilege");

		//close token handle
		CloseHandle(hToken);

		//indicate failure
		return RTN_ERROR;
	}

	return dwRetVal;
}
</code></pre>
<p dir="auto">I want to know how can i send some text from these files to my mainw ui</p>
]]></description><link>https://forum.qt.io/post/636159</link><guid isPermaLink="true">https://forum.qt.io/post/636159</guid><dc:creator><![CDATA[saeid0034]]></dc:creator><pubDate>Wed, 06 Jan 2021 12:41:57 GMT</pubDate></item><item><title><![CDATA[Reply to Send a text to textEdit from a non qt cpp file on Wed, 06 Jan 2021 12:32:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/saeid0034">@<bdi>saeid0034</bdi></a><br />
<code>SetPrivilege</code>/<code>CreateRemoteThread</code> have nothing to do with getting text from anywhere.</p>
<p dir="auto">This is 100% native Windows code, no relation to Qt, and no idea what kind of help you are looking for anyway.  Why you need to be using these native Windows functions and threads at all I have no idea; if you <em>really</em> need threads why not use <code>QThread</code>s in a Qt program?</p>
]]></description><link>https://forum.qt.io/post/636156</link><guid isPermaLink="true">https://forum.qt.io/post/636156</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 06 Jan 2021 12:32:13 GMT</pubDate></item></channel></rss>