473,473 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to avoid mixing processing and interfaces - How to replace cout?

2 New Member
I bet that others came across this problem and that there is a very good general solution, however I have not been able to get this done.

In short: How to replace std::cout by something that writes in a dialog box without mixing my code with some monstrous class library such as in Qt4, or for Windows Microsoft's class libraries.

The details of this implementation should not matter for this question. The only thing that matters is that I've got a bunch of C++ classes and one function that uses all the methods in there to parse an input string according to a particular grammar, and spit out a new string (or several). Let's call it the pattern-machine, and it works just fine, so far. Before I proceed developing it, I want to make it part of a system that makes use of dialog windows. In particular, I want to use Qt4 (under Linux/Fedora but convertible to windows).

Reading around in the examples and tutorials, I find that Qt4 basically has it's own standard library, but now everything is called a Q-something, QString, QList, Qwhatever. The claim is that std-lib and Qt4 can all be mixed but how to convert objects between the two isn't clear at all: What if I don't even want to change any of my already developed include files, where all is based on the standard C++ library?

I implemented everything so far simply and exclusively using standard output via std::cout, and also file output. Currently I would like to just replace std::cout by something from a different system. I thought I could just include a reference of type ostream& in my class as a member and write everything to that object, but the compiler doesn't allow this, and I think I'm on the wrong path.

Eagerly awaiting pearls of wisdom......
Jun 15 '07 #1
3 2008
weaknessforcats
9,208 Recognized Expert Moderator Expert
You can replace std::cout with anything you want provided:

1) your class derives from ostream.
2) implements a char data stream

Sounds like you re re-inventing Windows. Maybe not such a good idea.
Jun 15 '07 #2
rewtedesco
2 New Member
Sounds like you re re-inventing Windows. Maybe not such a good idea.
That wasn't really my plan :-)

I read a little bit more in the meantime on how to integrate code with Qt4 (Troll tech). I guess this is how I will proceed: In my class I'll replace all occurrences of "cout << something" by a similar operation to a string stream class. So I have to find some object in the Troll's forest of some 5000 Qobjects that can accept these strings and display them in a window (looks like QtextEditor could be abused for that), alternatively I can also use directly one of their Qtextstream classes which looks just like cout, and hook that up with output to a window. Looks like a problem is then to be able to convert std::strings into Qt strings and back (seems trivial but may not be, I saw some discussions about this elsewhere ).

So I'll end up having to write a piece of code that includes my headers and the Qt headers to make an object which inherits both my main class and a Qt class. This beast then should be able to receive and emit signals, as well as fetch and send strings (and convert from one version of strings to the other back and forth). An objective is to not have a single line of extra code that has to do with Qt in the code I ready wrote. Let's see how much headache this is going to bee.....
Jun 15 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
Quote:
Originally Posted by weaknessforcats
Sounds like you re re-inventing Windows. Maybe not such a good idea.


That wasn't really my plan :-)
There is a book: "Programming the STL" that might help you.
Jun 16 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Steven Quail | last post by:
Hi to all, Having come from a delphi environment, I remember that when using interfaces, we were told not to mix the object models and interface models. In other words, when I create an object,...
3
by: J Trauntvein | last post by:
I was working with a co-worker the other day to work through the process of formatting numeric values by imbueing C++ iostreams with locales. His program's initialisation code had a call to...
22
by: RSH | last post by:
Hi, I have been reading on interfaces working on samples I've run across on the web. For the life of me I cannot seem to grasp them. It appears to me that interfaces are simply blueprints to...
5
by: B. Williams | last post by:
I need some assistance with random access file processing. I have a function that I would like to change from sequential file processing to random access. Thanks in advance. void...
18
by: desktop | last post by:
I have 3 types of objects: bob1, bob2 and bob3. Each object is identified by a unique ID which gets returned by the function getId(). All bobs are descendants from class BaseBob which is an...
0
by: victarus | last post by:
I just thought I'd put this out here to get others' opinions on the concept. By no means do I claim to be a C++ guru (I'm really new, to be honest), but it just struck me as a pretty neat thing...
14
by: DavidNorep | last post by:
I do not know PHP, consider to write a CGI with this technology and have the following question. Is it possible to invoke a PHP script and let it endlessly wait for requests from a website (a...
2
by: Ralf Goertz | last post by:
Hi, can I mix output to cout and wcout? It seems that if I write to cout first it works fine but if I start with wcout the output to cout vanishes. I assume that is has to do with the...
26
by: Chris Becke | last post by:
Given an interface (in the c++ sense, nothing more than a struct containing pure virtual methods) struct Iv1 { virtual method0()=0; }; And a class that implements the interface class...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.