|
From what you are saying, you really don't want a vector or QtWidgets, you want a vector of QtWidgets that have a loadGUI method. Thus, you can do this:
class Base
{
public:
virtual void loadGUI() = 0;
virtual void reset() = 0;
};
class MyWidget : public QtWidget,
public virtual Base
{
virtual void loadGUI() {}
virtual void reset() {}
};
Then, in your code, you will create your MyWidgets and place them in a vector:
vector<Base*> myVector;
for (int i = 0; i < 5; ++i)
{
myVector.push_back(new MyWidget);
}
Then, whenever you decide to call your methods:
void loadGUIs(const MyWidget*& widget)
{
widget->loadGUI();
}
for_each(myVector.begin(), myVector.end(), loadGUIs);
As a side note: You will notice that I did not create a loop to iterate through the vector. You should use the algorithms as much as possible -- it will save you a LOT of headaches.
-- modified at 15:04 Monday 31st July, 2006
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thank you for your help,
@hfry:
My compiler (Visual Studio 2003) has problems with the following lines:
V.push_back(new Wrapper(new A));<br />
V.push_back(new Wrapper(new B));
The code output is "If you use a template class a template argument list is nessesary!" (translation from german).
After playing with the code I'm able to compile the wrapper class without pointer:
Wrapper<A> myWrapper(A); // with class 'A'
@Zac:
At this morning I produced a similar solution like you:
class Base : public QWidget<br />
{<br />
public:<br />
virtual void loadGUI() = 0;<br />
virtual void reset() = 0;<br />
};<br />
<br />
class MyWidget : public Base<br />
{<br />
virtual void loadGUI() {}<br />
virtual void reset() {}<br />
};<br />
<br />
vector<Base*> V;<br />
<br />
V.push_back(new MyWidget);<br />
...
But your solution is better. First your base class doesn't care about QWidgets (= less/simple code). Second your advise to use stl-algorithms for a good health (I only want headaches with a lot of beer at the next party!).
Bye,
Thomas
|
|
|
|
|
How to CComBSTR convert to char *?
alantop
|
|
|
|
|
USES_CONVERSION;
CComBSTR *pBString;
...
...
char *pString = OLE2T(pBString);
This should work.
The original point and click interface was a Smith & Wesson.
|
|
|
|
|
You're far better off with CW2A() et al (ATL7 and later). USES_CONVERSION is a biiiiiiig cludge. (Take a peek under the hood, and you'll see...)
--
Mr. Bender's Wardrobe by ROBOTANY 500
|
|
|
|
|
|
Do you have to use CComBSTR? If not, why are you using it? _bstr_t is a much more complete wrapper for BSTRs.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
If you want to eliminate CRT dependencies, CComBSTR is the way to go.
--
Broadcast simultaneously one year in the future
|
|
|
|
|
I have created a Child Window with its style set to WS_VSCROLL. This child window houses some CEdit and CStatic Windows. Now I have set up the Vertical Scroll bar, but when I scroll the child Window, the controls on it do not get repainted properly. Can anyone explain why?
I am using WTL 7.1. Thanks.
---
Hakuna-Matada
It means no worries for the rest of your days...
It's our problem free, Philosophy
<marquee behavior="alternate" scrollamount="5" scrolldelay="50">
|
|
|
|
|
Did you try to set clipchildrens style bit (forgot the actual name), if that doesn't work try calling UpdateWindow for all the controls after scrolling.
My sins are bloody red, my coffee is a black hole.
|
|
|
|
|
Thank You for taking the time to reply to my woe. Well, I have set the WS_CLIPCHILDREN and WS_CLIPSIBLINGS styles to my control and UpdateWindow() also doesn't work. In the End, I tried Invalidate on all the child controls and it worked. although the scrolling is not smooth as expected, but it scrolls. Any other way that I can make the scrolling experience better?
Thank You once again.
---
Hakuna-Matada
It means no worries for the rest of your days...
It's our problem free, Philosophy
<marquee behavior="alternate" scrollamount="5" scrolldelay="50">
|
|
|
|
|
how to trap tab change event in IE7 or how to get active tab ?
|
|
|
|
|
i found the way to get tab change event and get the active tab.
|
|
|
|
|
Would you mind sharing it with us?
|
|
|
|
|
Hello,
I create a COM componet with ATL, but when I test it , by CoCreateInstance(),
the result value is always E_OUTOFMEMORY, who can tell me why? Thanks a lot!
|
|
|
|
|
chenxiujie wrote: I create a COM componet with ATL, but when I test it , by CoCreateInstance(),
the result value is always E_OUTOFMEMORY
Search the Support Knowledge Base[^]
|
|
|
|
|
Hi,
I'm creating dll using VS2005 ATL project. I'm using third party SDK API's which extracts data into a *string variable. Now I'm facing problem with converting the *string to _bstr_t and *BSTR.
Please guide me whether is it possible to convert *string to _bstr_t and *BSTR, if so how to do it. If possible with a sample piece of code.
thanking you,
Arun
|
|
|
|
|
Hello agarunk,
By "*string", do you mean a pointer to a STL string ?
By "*BSTR", do you mean a pointer to a BSTR ?
- Bio.
|
|
|
|
|
Hi Bio,
Its "std::string* ", i.e., pointer to std string.
and yes "BSTR* " is pointer to a BSTR.
-Arun
|
|
|
|
|
Both the _bstr_t wrapper class and BSTR expect the text to be UNICODE, rather than ANSI or MBCS. While _bstr_t can convert from LPCSTR, BSTR on it's own can't.
You will need to use the c_str() member function of the std::string to get your LPCSTR in the first place (unlike MFC/ATL/WTL CString class, there's no LPCTSTR operator). Like I say, you can then use this pointer with something like A2W or MultiByteToWideChar.
Steve S
Developer for hire
|
|
|
|
|
Hi Steve,
Below is the implementation which I'm using now....
BSTR* TargetBSTR ;<br />
string *SourceStr=new string;<br />
string StrBuff;<br />
const char *CharBuff;<br />
<br />
StrBuff=*SourceStr;<br />
CharBuff=StrBuff.c_str();<br />
*TargetBSTR = _com_util::ConvertStringToBSTR(CharBuff);
Is this what you are asking me to do???
It is working fine for me for time being... I would like to know if I'm doing any mistake.
Is there any issues with it???
-Arun
|
|
|
|
|
agarunk wrote: BSTR* TargetBSTR ;
string *SourceStr=new string;
string StrBuff;
const char *CharBuff;
StrBuff=*SourceStr;
CharBuff=StrBuff.c_str();
*TargetBSTR = _com_util::ConvertStringToBSTR(CharBuff);
That is far more code than you need to do for this. See my response below.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Steve S wrote: Both the _bstr_t wrapper class and BSTR expect the text to be UNICODE, rather than ANSI or MBCS. While _bstr_t can convert from LPCSTR, BSTR on it's own can't.
This isn't completely accurate. _bstr_t has a constructor that takes a const char* . It will do the conversion for you.
Basically, if you need to convert std::string* to a _bstr_t* (or even to a BSTR* ), here is a simple way to do it:
std::string* pStlString = new string("my stuff");
_bstr_t* pBstrWrapper = new _bstr_t(pStlString->c_str());
BSTR* pBstr = pBstrWrapper->GetAddress();
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I sit corrected
I confess that these days I very rarely use ANSI/MBCS, since I no longer do stuff for Win9x/ME platforms. Lucky me, my end-customers all use W2K or later...
Steve S
Developer for hire
|
|
|
|
|
Since I'm in the Linux world at my new job, I'm a bit rusty myself. I do find that using the T-functions (along with classes that can use both char* and wchar_t*) alleviates much of those headaches.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|