<?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[Überladen von ostream]]></title><description><![CDATA[<p>Hi,</p>
<p>ich möchte den ostream an ein QTextEdit umleiten.</p>
<p>In einem QT-Programm möchte ich alle Ausgabe komfortabel mit dem std::cout in ein QTextEdit schicken. Das soll für alle Standardtypen, die ostream kennt funktionieren und für Objekte vom Typ QString.</p>
<p>Ich habe schonmal was angefangen und bin direkt an meine Grenzen gestoßen:</p>
<pre><code class="language-cpp">class LabelTest : public QWidget
{
Q_OBJECT

public:
      LabelTest(QWidget *parent = 0);

private:
      QTextEdit *text;

};
std::ostream&amp; operator &lt;&lt; (std::ostream&amp; os, const QString&amp; qs);

LabelTest::LabelTest(QWidget *parent) : QWidget(parent)
{
	text = new QTextEdit(&quot;Das hier steht schonmal drin&quot;, parent);

	// layout
	QVBoxLayout *layout = new QVBoxLayout;

	text-&gt;append(&quot;Juhu, was Neues!!!&quot;);

	layout-&gt;addWidget(text);
	setLayout(layout);

	text-&gt;append(&quot;Das hier geht&quot;);
	QString test(&quot;das nicht&quot;);
	std::cout &lt;&lt; test;

}

std::ostream&amp; operator &lt;&lt; (std::ostream&amp; os, const QString&amp; qs)
{
	//os &lt;&lt; qs.toStdString();
	text-&gt;append(qs); 
	return os;
}
</code></pre>
<p>Mein Problem: label ist nicht global und soll es auch nicht werden. Trotzdem sollte std::ostream&amp; operator &lt;&lt; (std::ostream&amp; os, const QString&amp; qs)<br />
label natürlich kennen und damit arbeiten dürfen.<br />
Wie kann man das erledigen?</p>
<p>Vielen Dank,</p>
<p>Karl</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/121578/überladen-von-ostream</link><generator>RSS for Node</generator><lastBuildDate>Sat, 22 Aug 2026 21:52:28 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/121578.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 25 Sep 2005 14:02:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Überladen von ostream on Sun, 25 Sep 2005 14:02:19 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich möchte den ostream an ein QTextEdit umleiten.</p>
<p>In einem QT-Programm möchte ich alle Ausgabe komfortabel mit dem std::cout in ein QTextEdit schicken. Das soll für alle Standardtypen, die ostream kennt funktionieren und für Objekte vom Typ QString.</p>
<p>Ich habe schonmal was angefangen und bin direkt an meine Grenzen gestoßen:</p>
<pre><code class="language-cpp">class LabelTest : public QWidget
{
Q_OBJECT

public:
      LabelTest(QWidget *parent = 0);

private:
      QTextEdit *text;

};
std::ostream&amp; operator &lt;&lt; (std::ostream&amp; os, const QString&amp; qs);

LabelTest::LabelTest(QWidget *parent) : QWidget(parent)
{
	text = new QTextEdit(&quot;Das hier steht schonmal drin&quot;, parent);

	// layout
	QVBoxLayout *layout = new QVBoxLayout;

	text-&gt;append(&quot;Juhu, was Neues!!!&quot;);

	layout-&gt;addWidget(text);
	setLayout(layout);

	text-&gt;append(&quot;Das hier geht&quot;);
	QString test(&quot;das nicht&quot;);
	std::cout &lt;&lt; test;

}

std::ostream&amp; operator &lt;&lt; (std::ostream&amp; os, const QString&amp; qs)
{
	//os &lt;&lt; qs.toStdString();
	text-&gt;append(qs); 
	return os;
}
</code></pre>
<p>Mein Problem: label ist nicht global und soll es auch nicht werden. Trotzdem sollte std::ostream&amp; operator &lt;&lt; (std::ostream&amp; os, const QString&amp; qs)<br />
label natürlich kennen und damit arbeiten dürfen.<br />
Wie kann man das erledigen?</p>
<p>Vielen Dank,</p>
<p>Karl</p>
]]></description><link>https://www.c-plusplus.net/forum/post/879664</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/879664</guid><dc:creator><![CDATA[Karl Blau]]></dc:creator><pubDate>Sun, 25 Sep 2005 14:02:19 GMT</pubDate></item><item><title><![CDATA[Reply to Überladen von ostream on Wed, 28 Sep 2005 22:11:00 GMT]]></title><description><![CDATA[<p>Oder macht man sowas vom Konzept her schon ganz anders?</p>
<p>Karl</p>
]]></description><link>https://www.c-plusplus.net/forum/post/882564</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/882564</guid><dc:creator><![CDATA[Karl Blau]]></dc:creator><pubDate>Wed, 28 Sep 2005 22:11:00 GMT</pubDate></item><item><title><![CDATA[Reply to Überladen von ostream on Thu, 29 Sep 2005 06:40:06 GMT]]></title><description><![CDATA[<p>mach einen freund daraus.</p>
<pre><code>friend std::ostream&amp; operator &lt;&lt; (std::ostream&amp; os, const hier_die_klasse&amp; qs);
</code></pre>
<p>mit in die klasse</p>
<p>jedoch überleg dir nochmal das objekt, dass du mit 'ostream' haben möchtest, und überlade für diese klasse die streams.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/882638</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/882638</guid><dc:creator><![CDATA[elise]]></dc:creator><pubDate>Thu, 29 Sep 2005 06:40:06 GMT</pubDate></item><item><title><![CDATA[Reply to Überladen von ostream on Thu, 29 Sep 2005 07:31:37 GMT]]></title><description><![CDATA[<p>Du musst einen eigenen Streambuffer schreiben und den Streambuffer von cout durch diesen ersetzen.<br />
Schau Dir mal diesen Thread an, da solltest Du alles an Startinfos finden:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-36062-and-highlight-is-streambuffer.html" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic-var-t-is-36062-and-highlight-is-streambuffer.html</a></p>
<p>Ansonsten, wenn Du den Josuttis hast, da wird das Thema auch recht gut behandelt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/882676</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/882676</guid><dc:creator><![CDATA[7H3 N4C3R]]></dc:creator><pubDate>Thu, 29 Sep 2005 07:31:37 GMT</pubDate></item><item><title><![CDATA[Reply to Überladen von ostream on Thu, 29 Sep 2005 07:43:54 GMT]]></title><description><![CDATA[<p>wxWidgets bietet eine Klasse <a href="http://wxwidgets.org/manuals/2.6.1/wx_wxstreamtotextredirector.html#wxstreamtotextredirector" rel="nofollow">wxStreamToTextRedirector</a> an,<br />
evtl. kannst du dir ja mal die Sourcen anschauen, oder QT bietet etwas ähnliches.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/882687</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/882687</guid><dc:creator><![CDATA[phlox81]]></dc:creator><pubDate>Thu, 29 Sep 2005 07:43:54 GMT</pubDate></item></channel></rss>