Qt principles
 
 
 

Main structure

The main structure is below.

Main Workflow

When MotionBuilder starts, QtSample DLL is loaded, but no QtSample instance is created. Only when a plugin is run, the QtSample, FBWidgeHolder and xxx instance are created like the below sequence:

Let’s see the track to the code to see details:

  1. DllMain (…) invokes FBModuleQtSample ().
  2. FBModuleQtSample () invokes FBObject_Register (…) (to register the QtSample class).
  3. FBObject_Register (…) invokes RegisterToolQTSAMPLE__CLASS (...)
  4. RegisterToolQTSAMPLE__CLASS (...) creates a QtSample instance, and invoke FBCreate() function.
  5. FBCreate () invokes UICreate () to create the UI.
  6. UICreate () invokes CreateQtTestWidget (…).
  7. CreateQtTestWidget (…) creates an xxx instance. (xxx is the UI class.)
  8. xxx constructor invoke ui.setupUi (this) to create the UI. setupUi () function can be found in ui_xxx.h file, which is generated by xxx.ui file by uic command.

Until now the UI has been created and shown in screen. But how to respond to the button click event?

  1. When you click the button, xxx::qt_metacall(…) will be invoked.
  2. on_buttonCreateCube_clicked() will be invoked to response the button click event.

MOC & UIC Commands

Do you feel strange about xxx::qt_metacall(…)? You haven't created it. Actually it is created when compiler creates moc_xxx.cpp files by MOC commands. Below graphic show you which file could generate which file by which command:

Each file’s responsibilities have been shown in below graphic:

You can find the use of UIC in xxx.ui file's property:

You can find the use of MOC in xxx.h file's property:

Where is DllMain?

You may get confused that you cannot find the DllMain(…) method, the DLL entry point. Actually it is generated by below MICRO in qtsample_tool.cpp file.

// Library declaration.
FBLibraryDeclare( qtsample )
{
	FBLibraryRegister( QtSample );
}
FBLibraryDeclareEnd;

After compiling the qtsample_tool.i file you can see it clearly:

static FBLibrary qtsampleGlobalFBLibrary; 
extern "C" 
{ 
    __declspec(dllexport) 
    bool LIBRARY_INIT(HIError ) 
    { 
        ; 
        if (qtsampleGlobalFBLibrary.LibInit()) 
            return true; 
        return false; 
    } 
} 

__declspec(dllexport) void EntryPointqtsample(kFBDllOperation Operation); 

BOOL __stdcall DllMain(HINSTANCE hinstDLL,DWORD fdwReason, LPVOID lpvReserved ) 
{ 
    switch (fdwReason) 
    { 
        case 1: EntryPointqtsample(kFBDllLoad); break; 
        case 0: EntryPointqtsample(kFBDllUnLoad); break; 
    } 
    return 1; 
}

void EntryPointqtsample(kFBDllOperation Operation) 
{ 
    switch( Operation ) 
    { 
        case kFBDllLoad: 
        {
            {    
                extern void FBModuleQtSample( ); 
                FBModuleQtSample( );;
            }
        }        break; 
        default: break; 
    } 
};

Something tricky