From owner-freebsd-ports@freebsd.org Fri Apr 15 16:37:10 2016 Return-Path: Delivered-To: freebsd-ports@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B5C24AEE95E for ; Fri, 15 Apr 2016 16:37:10 +0000 (UTC) (envelope-from FreeBSD@shaneware.biz) Received: from ipmail04.adl6.internode.on.net (ipmail04.adl6.internode.on.net [150.101.137.141]) by mx1.freebsd.org (Postfix) with ESMTP id 2A06514C2; Fri, 15 Apr 2016 16:37:09 +0000 (UTC) (envelope-from FreeBSD@shaneware.biz) Received: from ppp118-210-182-127.lns20.adl6.internode.on.net (HELO leader.local) ([118.210.182.127]) by ipmail04.adl6.internode.on.net with ESMTP; 16 Apr 2016 02:07:08 +0930 Subject: Re: Need some help with c++/qt5 code To: Raphael Kubo da Costa , freebsd-ports@freebsd.org References: <570F85E3.6060000@ShaneWare.Biz> <86inzjdq4w.fsf@FreeBSD.org> From: Shane Ambler Message-ID: <571118B0.3020806@ShaneWare.Biz> Date: Sat, 16 Apr 2016 02:07:04 +0930 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: <86inzjdq4w.fsf@FreeBSD.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Apr 2016 16:37:10 -0000 On 15/04/2016 21:45, Raphael Kubo da Costa wrote: > Dimitry Andric writes: > >> On 14 Apr 2016, at 13:58, Shane Ambler 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 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 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 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(). Thanks that does the trick. -- FreeBSD - the place to B...Software Developing Shane Ambler