Results 1 to 3 of 3

Thread: Migrating content from header file to source file

  1. #1
    Join Date
    Sep 2012
    Posts
    31
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Question Migrating content from header file to source file

    Hi,I am trying out an implementation for my header and source files with a user interface.
    The default for Qt is that it generates the form below for the header and source files when using the wizard.
    For example I wanted to create a class using QWidget as its base class.

    the header file is:


    #include <QWidget>
    #include <QCloseEvent>
    #include <QMessageBox>

    namespace Ui{

    class frmBitMainPanel;
    }

    class BitMainPanel : public QWidget
    {

    Q_OBJECT

    public:
    explicit BitMainPanel(QWidget *ParentPtr = 0);


    private:

    Ui::frmBitMainPanel *UiPanelPtr;

    protected:
    void closeEvent(QCloseEvent *);



    the source file is:


    BitMainPanel::BitMainPanel(QWidget *ParentPtr) : QWidget(ParentPtr), UiPanelPtr(new Ui::frmBitMainPanel)
    {

    UiPanelPtr->setupUI(this);
    }

    --question is, if I were to implement my headers to only contain function prototypes and the source files to contain the declarations such as the Ui::frmBitMainPanel *UiPanelPtr how would I go on about this?

    I am going to migrate Ui::frmBitMainPanel *UiPanelPtr to the source file. Same goes with all future declarations. Is it possible?






  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,734
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Migrating content from header file to source file

    Not in the sense I think you are expecting: there will be some private data in almost every useful class.

    However, the private implementation idiom (AKA pimpl or handle pattern) will get you much of the way there. You have a forward declaration and a single pointer to a private class in the public header and everything else about the private class is, well, private and used only from the CPP file. This maximises binary compatibility by minimising the exposed implementation details... which, I assume, is the unstated reason for wanting to do this.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Migrating content from header file to source file

    If I can add to what Chris already said -- the schema posted in this thread already uses the private implementation idiom -- note, that Ui::frmBitMainPanel is only forward declared in the header file and all its implementation details are hidden by including ui_xxxx.h in the cpp file only. Units using the header file are only informed that "somewhere there may exist a class called Ui::frmBitMainPanel".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Erasing the content of a txt file
    By Momergil in forum Newbie
    Replies: 7
    Last Post: 2nd August 2011, 15:10
  2. encrypt the content of a file
    By franco.amato in forum Qt Programming
    Replies: 9
    Last Post: 11th May 2011, 16:35
  3. Replies: 12
    Last Post: 22nd March 2011, 15:08
  4. QDomDocument can't read the file content
    By baluk in forum Newbie
    Replies: 21
    Last Post: 24th September 2010, 13:43
  5. set content(&file)
    By rk0747 in forum Qt Programming
    Replies: 1
    Last Post: 6th February 2010, 08:31

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.