I have a problem I've been working on for days now with global variable
use. I'm currently using QT for development but this same problem
should apply to anytime a C++ object is trying to be used globally.
Just assume the QT stuff is fine and that they are predefined library
objects. Anyway, I want to have a global QTextStream object that I use
to print debug information to. This program compiles fine, but if I
ever try to use my global QTextStream object it gives me the error:
"binary '<<' : no operator found which takes a left-hand operand of
type 'QTextStream'"
Any suggestions would be much appreciated. Thanks,
Chris
Here's all the relevant code:
DEBUG.H:
#ifndef DEBUG_H
#define DEBUG_H
#include <QMainWindow>
#include <QLabel>
#include <QTextStream>
#include <QSTring>
#include <QBuffer>
static QTextStream debugout;
class Debug : public QMainWindow
{
Q_OBJECT
public:
QLabel debugLabel;
QByteArray debugArray;
QBuffer debugBuffer;
Debug();
private:
private slots:
void textWritten(int numBytes);
};
#endif
DEBUG.CPP:
#include "Debug.h"
Debug::Debug()
{
setCentralWidge t(&debugLabel) ;
debugout.setDev ice(&debugBuffe r);
connect(&debugB uffer, SIGNAL(bytesWri tten(int)), this,
SLOT(textWritte n(int)));
}
void Debug::textWrit ten(int numBytes)
{
QByteArray newText = debugBuffer.rea dAll();
debugArray.appe nd(newText);
debugLabel.setT ext(debugArray) ;
} 2 11009
Chris Portka wrote:
I have a problem I've been working on for days now with global variable
use. I'm currently using QT for development but this same problem
should apply to anytime a C++ object is trying to be used globally.
Just assume the QT stuff is fine and that they are predefined library
objects. Anyway, I want to have a global QTextStream object that I use
to print debug information to. This program compiles fine, but if I
ever try to use my global QTextStream object it gives me the error:
"binary '<<' : no operator found which takes a left-hand operand of
type 'QTextStream'"
Any suggestions would be much appreciated. Thanks,
Chris
Here's all the relevant code:
DEBUG.H:
#ifndef DEBUG_H
#define DEBUG_H
#include <QMainWindow>
#include <QLabel>
#include <QTextStream>
#include <QSTring>
#include <QBuffer>
static QTextStream debugout;
Suggestion #1) Don't do that. Look at the docs for QDebug.
Suggestion #2) Post to qt*********@tro lltech.com Your question really is
Qt-specific.
Suggestion #3) Don't do that. Globals are ugly.
Suggestion #4) http://doc.trolltech.com/4.2/qtextst...tml#setPadChar
QString s;
QTextStream out(&s);
out.setFieldWid th(10);
out.setPadChar( '-');
out << "Qt" << endl << "rocks!" << endl;
--
NOUN:1. Money or property bequeathed to another by will. 2. Something handed
down from an ancestor or a predecessor or from the past: a legacy of
religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF,
from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/
Steven T. Hatton a écrit :
Chris Portka wrote:
>I have a problem I've been working on for days now with global variable use. I'm currently using QT for development but this same problem should apply to anytime a C++ object is trying to be used globally. Just assume the QT stuff is fine and that they are predefined library objects. Anyway, I want to have a global QTextStream object that I use to print debug information to. This program compiles fine, but if I ever try to use my global QTextStream object it gives me the error: "binary '<<' : no operator found which takes a left-hand operand of type 'QTextStream'" Any suggestions would be much appreciated. Thanks, Chris
Here's all the relevant code:
DEBUG.H:
#ifndef DEBUG_H #define DEBUG_H
#include <QMainWindow> #include <QLabel> #include <QTextStream> #include <QSTring> #include <QBuffer>
static QTextStream debugout;
[...]
Suggestion #3) Don't do that. Globals are ugly.
[...]
Yes, ugly. Especially declared static in a header file.
Use static within a class to make it global to the class but otherwise,
use extern.
in debug.hpp:
....
extern QTextStream debugout;
....
in debug.cpp
....
QTextStream debugout;
.... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Clifford W. Racz |
last post by:
Has anyone solved the issue of translating lists in Word 2003 (WordML)
into xHTML? I have been trying to get the nested table code for my XSLT
to work for a while now, with no way to get the collection that I need.
To begin, I am using xsltproc that conmes with Cygwin as my processor.
I have no particular affinity to this processor except that it is open
source and standards compliant. I don't like M$, but if using a M$
processing...
|
by: Kleenex |
last post by:
Reason: I am working on an embedded project which has very limited
memory (under 512 bytes, 60 or so of which is stack space), which
translates into limited stack space. In order to save on stack space, I
tried to only use parameters and stack space for things which are truely
temporary. Instead of passing a pointer to a data structure which should
always be populated with data, I have the data structure declared as a
global variable and...
|
by: ajikoe |
last post by:
Hi,
I tried to follow the example in swig homepage.
I found error which I don't understand.
I use bcc32, I already include directory where my python.h exist in
bcc32.cfg.
/* File : example.c */
#include <time.h>
|
by: shaun |
last post by:
If I put (define) const variables at the top of a .cpp file but do not
declare them in the .h file, are they only visible within that .cpp file?
e.g.
const int a={1,2,3,4};
in a cpp file will be a 'global' with file scope? (no flames for
oxymoron, please), available for use inside my functions which are
defined in the same file (but which are also declared in the .h)?
|
by: zeecanvas |
last post by:
Hi,
First of all: Yes, I know global variables are bad, but I've a huge
amount of legacy code, and I've to maintain it _as_is_.
I'm maintaining a big program. I moved all (program-wide scope) global
variables outside of the files they were defined it, and created some
files that just hold global variables definitions (just variables,
without any function definition). So, depending on the purpose/category
of variables, they're defined...
| |
by: Roman Ziak |
last post by:
Hello,
there were times when I used to be looking for a way to access
JavaScript Global object similar to those found in VBScript or PHP
($GLOBALS). At present this has only academic value for me. I was doing
research on JavaScript inheritance recently (simplifying it in
particular) and after reading 10.1.1, 10.1.3 and some other sections of
ECMA262 I got a hint on accessing global object from different than
global scope.
|
by: Ed Jensen |
last post by:
I'm having a vexing problem with global variables in Python. Please
consider the following Python code:
#! /usr/bin/env python
def tiny():
bar =
for tmp in foo:
bar.append(tmp)
foo = bar
|
by: istillshine |
last post by:
When I control if I print messages, I usually use a global variable
"int silent". When I set "-silent" flag in my command line
parameters, I set silent = 1 in my main.c.
I have many functions that may print some messages.
foo(...)
{
if (!silent)
|
by: Jaco Naude |
last post by:
Hi,
I'm using a static library in my application which links fine except
for a few global variables. The static library only contains a bunch
of .cpp and .h files and the global variables are defined as follows:
extern unsigned mgl_numg, mgl_cur;
extern float mgl_fact;
extern long mgl_gen_fnt;
extern short mgl_buf_fnt;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |