Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, May 2007
How to initialize a static QStringList?


Message 1 in thread

How to initialize a static QStringList?

I have class static QStringList declared as public in .h
class NamePen : public QObject
{
Q_OBJECT
public:
static QStringList PenStyles, PenCapStyles, PenJoinStyles;
// . . .
}

In the corresponding cpp, I put there definitions:
QStringList NamePen::PenStyles, NamePen::PenCapStyles, 
NamePen::PenJoinStyles;

But I have no idea where should I put initialize them.
I subclass QApplication and put the initialization part into its 
constructor.
It doesn’t work well.

Thanks in advance,
Lingfa


--
 [ signature omitted ] 

Message 2 in thread

just do for each QStringList something like this (in ur cpp file  
ofcourse):
QStringList NamePen::PenStyles = QStringList();

All should work well

On May 21, 2007, at 8:25 PM, Lingfa Yang wrote:

> How to initialize a static QStringList?
>
> I have class static QStringList declared as public in .h
> class NamePen : public QObject
> {
> Q_OBJECT
> public:
> static QStringList PenStyles, PenCapStyles, PenJoinStyles;
> // . . .
> }
>
> In the corresponding cpp, I put there definitions:
> QStringList NamePen::PenStyles, NamePen::PenCapStyles,  
> NamePen::PenJoinStyles;
>
> But I have no idea where should I put initialize them.
> I subclass QApplication and put the initialization part into its  
> constructor.
> It doesn’t work well.
>
> Thanks in advance,
> Lingfa
>
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx  
> with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>

--
 [ signature omitted ] 

Message 3 in thread

On 21.05.07 20:34:28, Naresh wrote:
> just do for each QStringList something like this (in ur cpp file ofcourse):
> QStringList NamePen::PenStyles = QStringList();
> 
> All should work well

And if you want to add some initial data extend this to

StringList NamePen::PenStyles = QStringList() << "Val1" << "Val2"...;

Andreas

-- 
 [ signature omitted ] 

Message 4 in thread

Andreas Pakulat wrote:

>On 21.05.07 20:34:28, Naresh wrote:
>  
>
>>just do for each QStringList something like this (in ur cpp file ofcourse):
>>QStringList NamePen::PenStyles = QStringList();
>>
>>All should work well
>>    
>>
>
>And if you want to add some initial data extend this to
>
>StringList NamePen::PenStyles = QStringList() << "Val1" << "Val2"...;
>
>Andreas
>
>  
>
Thanks both Naresh and Andreas.

It does not work.

QStringList NamePen::PenJoinStyles = (QStringList()
        << "MiterJoin"
        << "BevelJoin"   
        << "RoundJoin"   
        );
At the moment I use it, program crashed!

Any more idea?

Lingfa


--
 [ signature omitted ] 

Message 5 in thread

On 21.05.07 15:49:13, Lingfa Yang wrote:
> Andreas Pakulat wrote:
> 
> >On 21.05.07 20:34:28, Naresh wrote:
> > 
> >>just do for each QStringList something like this (in ur cpp file ofcourse):
> >>QStringList NamePen::PenStyles = QStringList();
> >>
> >>All should work well
> >>   
> >
> >And if you want to add some initial data extend this to
> >
> >StringList NamePen::PenStyles = QStringList() << "Val1" << "Val2"...;
> >
> >Andreas
> >
> > 
> Thanks both Naresh and Andreas.
> 
> It does not work.
> 
> QStringList NamePen::PenJoinStyles = (QStringList()
>        << "MiterJoin"
>        << "BevelJoin"          << "RoundJoin"          );
> At the moment I use it, program crashed!

Where did you get the () around the whole thing from? As I wrote:

QStringList NamePen::PenStyles = QStringList() << "Foo" << "Bar";

works fine.

Andreas

-- 
 [ signature omitted ] 

Message 6 in thread

On 21.05.07 16:02:52, Lingfa Yang wrote:
> Andreas Pakulat wrote:
> >On 21.05.07 15:49:13, Lingfa Yang wrote:
> >>Andreas Pakulat wrote:
> >>>On 21.05.07 20:34:28, Naresh wrote:
> >>>>just do for each QStringList something like this (in ur cpp file ofcourse):
> >>>>QStringList NamePen::PenStyles = QStringList();
> >>>>
> >>>>All should work well
> >>>>        
> >>>And if you want to add some initial data extend this to
> >>>
> >>>StringList NamePen::PenStyles = QStringList() << "Val1" << "Val2"...;
> >>>
> >>Thanks both Naresh and Andreas.
> >>
> >>It does not work.
> >>
> >>QStringList NamePen::PenJoinStyles = (QStringList()
> >>      << "MiterJoin"
> >>      << "BevelJoin"          << "RoundJoin"          );
> >>At the moment I use it, program crashed!
> >>   
> >
> >Where did you get the () around the whole thing from? As I wrote:
> >
> >QStringList NamePen::PenStyles = QStringList() << "Foo" << "Bar";
> >
> >works fine.
> > 
> I removed "()" that's the same.

Please don't write to me in private.

If it doesn't work for you we need at least the compiler messages or a
backtrace if it crashes and some more code (if possible create a minimal
compilable example).

Andreas


-- 
 [ signature omitted ] 

Message 7 in thread

Andreas Pakulat wrote:

>On 21.05.07 20:34:28, Naresh wrote:
>  
>
>>just do for each QStringList something like this (in ur cpp file ofcourse):
>>QStringList NamePen::PenStyles = QStringList();
>>
>>All should work well
>>    
>>
>
>And if you want to add some initial data extend this to
>
>StringList NamePen::PenStyles = QStringList() << "Val1" << "Val2"...;
>
>Andreas
>
>  
>
The problem is much wired!
I put there three in parallel ways. The first two works, but the third 
one crashes! (see attached 1.c)

Lingfa

QStringList  NamePen::PenStyles = QStringList()
QStringList  NamePen::PenStyles = QStringList()
		<< "NoPen"          // 0 no line at all. For example, QPainter::drawRect() fills but does not draw any boundary line.
		<< "SolidLine"      // 1 A plain line.
		<< "DashLine"       // 2 Dashes separated by a few pixels.
		<< "DotLine"        // 3 Dots separated by a few pixels.
		<< "DashDotLine"    // 4 Alternate dots and dashes.
		<< "DashDotDotLine" // 5 One dash, two dots, one dash, two dots.
		<< "CustomDashLine" // 6 A custom pattern defined using QPainterPathStroker::setDashPattern().
		;
	
QStringList  NamePen::PenCapStyles = QStringList()
		<< "FlatCap"	// 0x00	a square line end that does not cover the end point of the line.
		<< "SquareCap"	// 0x10	a square line end that covers the end point and extends beyond it by half the line width.
		<< "RoundCap"	// 0x20	a rounded line end.
		;
QStringList NamePen::PenJoinStyles = QStringList() 
		<< "MiterJoin"	// 0x00	The outer edges of the lines are extended to meet at an angle, and this area is filled.
		<< "BevelJoin"	// 0x40	The triangular notch between the two lines is filled.
		<< "RoundJoin"	// 0x80	A circular arc between the two lines is filled.
		;




	int size1 = NamePen::PenStyles.size();		// 7
	int size2 = NamePen::PenCapStyles.size();	// 3
	int size3 = NamePen::PenJoinStyles.size();	// crash!

Message 8 in thread

On 21.05.07 16:15:28, Lingfa Yang wrote:
> Andreas Pakulat wrote:
> 
> >On 21.05.07 20:34:28, Naresh wrote:
> > 
> >>just do for each QStringList something like this (in ur cpp file ofcourse):
> >>QStringList NamePen::PenStyles = QStringList();
> >>
> >>All should work well
> >>   
> >
> >And if you want to add some initial data extend this to
> >
> >StringList NamePen::PenStyles = QStringList() << "Val1" << "Val2"...;
> >
> >Andreas
> >
> > 
> The problem is much wired!
> I put there three in parallel ways. The first two works, but the third one 
> crashes! (see attached 1.c)

Whats the backtrace? How does the full test program look like?

Andreas

-- 
 [ signature omitted ] 

Message 9 in thread

>Whats the backtrace? How does the full test program look like?
>
>Andreas
>
>  
>
I finally figured out the problem come from a separated boundary mistake 
which request memory from stack.

The standard ways of declaration, definition and initiation work well 
for static QStringList.

Thanks.
Lingfa


--
 [ signature omitted ]