[prev in list] [next in list] [prev in thread] [next in thread]
List: freebsd-ports
Subject: Re: Need some help with c++/qt5 code
From: Raphael Kubo da Costa <rakuco () FreeBSD ! org>
Date: 2016-04-15 12:15:43
Message-ID: 86inzjdq4w.fsf () FreeBSD ! org
[Download RAW message or body]
Dimitry Andric <dim@FreeBSD.org> writes:
> On 14 Apr 2016, at 13:58, Shane Ambler <FreeBSD@ShaneWare.Biz> wrote:
>>
>> Hi there, while I am comfortable with c and python, I only know a little
>> c++ and could use some help.
> ...
>> class TPanelFactory
>> {
>> QString m_panelType;
>> static QMap<QString, TPanelFactory *> m_table;
>>
>> public:
>> TPanelFactory(QString panelType);
>> ~TPanelFactory();
>>
>> QString getPanelType() const { return m_panelType; }
>>
>> virtual void initialize(TPanel *panel) = 0;
>> virtual TPanel *createPanel(QWidget *parent);
>> static TPanel *createPanel(QWidget *parent, QString panelType);
>> };
>>
>> m_table is then in the source file as
>>
>> QMap<QString, TPanelFactory *> TPanelFactory::m_table;
>>
>> The segfault happens in the constructor -
>>
>> TPanelFactory::TPanelFactory(QString panelType)
>> : m_panelType(panelType)
>> {
>> assert(m_table.count(panelType) == 0);
>> m_table[m_panelType] = this;
>> }
>>
>> the last line causes the segfault, if I comment it out then main() is
>> entered, but I expect removing that line will bite back soon enough.
>>
>> How can I get this working?
>>
>> Why would this fail on FreeBSD but not OSX or windows?
>
> Most likely the program depends on the initialization order of global
> constructors. This is bad practice, and should be avoided.
I agree. Maybe using Q_GLOBAL_STATIC helps?
- Remove m_table from TPanelFactory.
- In pane.cpp, you do something like this:
typedef QMap<QString, TPanelFactory *> PanelMapType;
Q_GLOBAL_STATIC(PanelMapType, s_panelMap);
you then need to replace uses of m_table with s_panelMap and use
s_panelMap->operation() instead of m_table.operation().
_______________________________________________
freebsd-ports@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ports
To unsubscribe, send any mail to "freebsd-ports-unsubscribe@freebsd.org"
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic