Loading ui at runtime



  • hi ,

    I am using qt 4.8.2 build on mingw on linux .
    I have problem loading ui file at run time .I have added ui form to resource file .I get segmentation fault. the following error is displayed
    Designer: An error has occurred while reading the UI file at line 1, column 0: Premature end of document.

    the following is the code

    QUiLoader loader;

    QFile file(":/forms/selectiondialog.ui");
    file.open(QFile::ReadOnly);
    
    QWidget *formWidget = loader.load(&file); // getting segmentation fault 
    file.close();
    

    thanks,
    hema


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Are you sure that selectiondialog.ui is found ?



  • the following is the error is what i am getting

    "<?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>Dialog</class>
    <widget class="QDialog" name="Dialog">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>322</width>
    <height>189</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>Dialog</string>
    </property>
    <layout class="QGridLayout" name="gridLayout_2">
    <item row="0" column="0" colspan="3">
    <layout class="QGridLayout" name="gridLayout">
    <item row="0" column="0">
    <widget class="QLabel" name="lbl_First">
    <property name="text">
    <string/>
    </property>
    </widget>
    </item>
    <item row="0" column="1">
    <widget class="QLabel" name="lbl_Second">
    <property name="text">
    <string/>
    </property>
    </widget>
    </item>
    <item row="1" column="0">
    <widget class="QListWidget" name="listWidget_Initial"/>
    </item>
    <item row="1" column="1">
    <widget class="QListWidget" name="listWidget_Final"/>
    </item>
    </layout>
    </item>
    <item row="1" column="0">
    <spacer name="horizontalSpacer_2">
    <property name="orientation">
    <enum>Qt::Horizontal</enum>
    </property>
    <property name="sizeHint" stdset="0">
    <size>
    <width>65</width>
    <height>20</height>
    </size>
    </property>
    </spacer>
    </item>
    <item row="1" column="1">
    <widget class="QDialogButtonBox" name="buttonBox">
    <property name="orientation">
    <enum>Qt::Horizontal</enum>
    </property>
    <property name="standardButtons">
    <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
    </property>
    </widget>
    </item>
    <item row="1" column="2">
    <spacer name="horizontalSpacer">
    <property name="orientation">
    <enum>Qt::Horizontal</enum>
    </property>
    <property name="sizeHint" stdset="0">
    <size>
    <width>65</width>
    <height>20</height>
    </size>
    </property>
    </spacer>
    </item>
    </layout>
    </widget>
    <resources/>
    <connections>
    <connection>
    <sender>buttonBox</sender>
    <signal>accepted()</signal>
    <receiver>Dialog</receiver>
    <slot>accept()</slot>
    <hints>
    <hint type="sourcelabel">
    <x>248</x>
    <y>254</y>
    </hint>
    <hint type="destinationlabel">
    <x>157</x>
    <y>274</y>
    </hint>
    </hints>
    </connection>
    <connection>
    <sender>buttonBox</sender>
    <signal>rejected()</signal>
    <receiver>Dialog</receiver>
    <slot>reject()</slot>
    <hints>
    <hint type="sourcelabel">
    <x>316</x>
    <y>260</y>
    </hint>
    <hint type="destinationlabel">
    <x>286</x>
    <y>274</y>
    </hint>
    </hints>
    </connection>
    </connections>
    </ui>
    "
    Designer: An error has occurred while reading the UI file at line 1, column 0: Premature end of document.


  • Lifetime Qt Champion

    Please enclose you code within coding tags so it will make it readable.

    I didn't state that the xml was wrong (it should not if you have generated it with designer) but did you check that file.open returns true ?



  • selectiondialog.ui
    file exists in the forms



  • K , but file.open is returing true


  • Lifetime Qt Champion

    Ok then, did you create the ui file yourself ?



  • sorry for a long delay ,
    this ui is created by myself
    I am calling this ui in one function funcn()
    funcn()
    {
    QFile file(":/forms/selectiondialog.ui");
    QWidget *selectionWidget = this->loadUiFile(file);
    }

    QWidget* OptimaRTools::loadUiFile(QFile& file1)
    {

    QUiLoader loader;
     QFile file&#40;":/forms/selectiondialog.ui"&#41;;
    file.open(QFile::ReadOnly);
    file.errorString();
    QWidget *formWidget = loader.load(&file);
    file.close();
    

    return formWidget;
    }

    and the ui file is

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>Dialog</class>
    <widget class="QDialog" name="Dialog">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>322</width>
    <height>189</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>Dialog</string>
    </property>
    <layout class="QGridLayout" name="gridLayout_2">
    <item row="0" column="0" colspan="3">
    <layout class="QGridLayout" name="gridLayout">
    <item row="0" column="0">
    <widget class="QLabel" name="lbl_First">
    <property name="text">
    <string/>
    </property>
    </widget>
    </item>
    <item row="0" column="1">
    <widget class="QLabel" name="lbl_Second">
    <property name="text">
    <string/>
    </property>
    </widget>
    </item>
    <item row="1" column="0">
    <widget class="QListWidget" name="listWidget_Initial"/>
    </item>
    <item row="1" column="1">
    <widget class="QListWidget" name="listWidget_Final"/>
    </item>
    </layout>
    </item>
    <item row="1" column="0">
    <spacer name="horizontalSpacer_2">
    <property name="orientation">
    <enum>Qt::Horizontal</enum>
    </property>
    <property name="sizeHint" stdset="0">
    <size>
    <width>65</width>
    <height>20</height>
    </size>
    </property>
    </spacer>
    </item>
    <item row="1" column="1">
    <widget class="QDialogButtonBox" name="buttonBox">
    <property name="orientation">
    <enum>Qt::Horizontal</enum>
    </property>
    <property name="standardButtons">
    <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
    </property>
    </widget>
    </item>
    <item row="1" column="2">
    <spacer name="horizontalSpacer">
    <property name="orientation">
    <enum>Qt::Horizontal</enum>
    </property>
    <property name="sizeHint" stdset="0">
    <size>
    <width>65</width>
    <height>20</height>
    </size>
    </property>
    </spacer>
    </item>
    </layout>
    </widget>
    <resources/>
    <connections>
    <connection>
    <sender>buttonBox</sender>
    <signal>accepted()</signal>
    <receiver>Dialog</receiver>
    <slot>accept()</slot>
    <hints>
    <hint type="sourcelabel">
    <x>248</x>
    <y>254</y>
    </hint>
    <hint type="destinationlabel">
    <x>157</x>
    <y>274</y>
    </hint>
    </hints>
    </connection>
    <connection>
    <sender>buttonBox</sender>
    <signal>rejected()</signal>
    <receiver>Dialog</receiver>
    <slot>reject()</slot>
    <hints>
    <hint type="sourcelabel">
    <x>316</x>
    <y>260</y>
    </hint>
    <hint type="destinationlabel">
    <x>286</x>
    <y>274</y>
    </hint>
    </hints>"
    </connection>
    </connections>
    </ui>


  • Lifetime Qt Champion

    Please use coding tags

    What do you mean by yourself ? Using the designer integrated with QtCreator ?



  • ui is created using Qt designer form



  • @<?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>Dialog</class>
    <widget class="QDialog" name="Dialog">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>322</width>
    <height>221</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>Dialog</string>
    </property>
    <widget class="QDialogButtonBox" name="buttonBox">
    <property name="geometry">
    <rect>
    <x>65</x>
    <y>187</y>
    <width>181</width>
    <height>32</height>
    </rect>
    </property>
    <property name="orientation">
    <enum>Qt::Horizontal</enum>
    </property>
    <property name="standardButtons">
    <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
    </property>
    </widget>
    <widget class="QWidget" name="layoutWidget">
    <property name="geometry">
    <rect>
    <x>10</x>
    <y>10</y>
    <width>301</width>
    <height>171</height>
    </rect>
    </property>
    <layout class="QGridLayout" name="gridLayout">
    <item row="0" column="0">
    <widget class="QLabel" name="lbl_First">
    <property name="text">
    <string/>
    </property>
    </widget>
    </item>
    <item row="0" column="1">
    <widget class="QLabel" name="lbl_Second">
    <property name="text">
    <string/>
    </property>
    </widget>
    </item>
    <item row="1" column="0">
    <widget class="QListWidget" name="listWidget_Initial"/>
    </item>
    <item row="1" column="1">
    <widget class="QListWidget" name="listWidget_Final"/>
    </item>
    </layout>
    </widget>
    </widget>
    <resources/>
    <connections>
    <connection>
    <sender>buttonBox</sender>
    <signal>accepted()</signal>
    <receiver>Dialog</receiver>
    <slot>accept()</slot>
    <hints>
    <hint type="sourcelabel">
    <x>248</x>
    <y>254</y>
    </hint>
    <hint type="destinationlabel">
    <x>157</x>
    <y>274</y>
    </hint>
    </hints>
    </connection>
    <connection>
    <sender>buttonBox</sender>
    <signal>rejected()</signal>
    <receiver>Dialog</receiver>
    <slot>reject()</slot>
    <hints>
    <hint type="sourcelabel">
    <x>316</x>
    <y>260</y>
    </hint>
    <hint type="destinationlabel">
    <x>286</x>
    <y>274</y>
    </hint>
    </hints>
    </connection>
    </connections>
    </ui>
    @


  • Lifetime Qt Champion

    What does print:

    @qDebug() << file.readAll();@

    ?



  • @"<?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>Dialog</class>
    <widget class="QDialog" name="Dialog">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>322</width>
    <height>189</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>Dialog</string>
    </property>
    <layout class="QGridLayout" name="gridLayout_2">
    <item row="0" column="0" colspan="3">
    <layout class="QGridLayout" name="gridLayout">
    <item row="0" column="0">
    <widget class="QLabel" name="lbl_First">
    <property name="text">
    <string/>
    </property>
    </widget>
    </item>
    <item row="0" column="1">
    <widget class="QLabel" name="lbl_Second">
    <property name="text">
    <string/>
    </property>
    </widget>
    </item>
    <item row="1" column="0">
    <widget class="QListWidget" name="listWidget_Initial"/>
    </item>
    <item row="1" column="1">
    <widget class="QListWidget" name="listWidget_Final"/>
    </item>
    </layout>
    </item>
    <item row="1" column="0">
    <spacer name="horizontalSpacer_2">
    <property name="orientation">
    <enum>Qt::Horizontal</enum>
    </property>
    <property name="sizeHint" stdset="0">
    <size>
    <width>65</width>
    <height>20</height>
    </size>
    </property>
    </spacer>
    </item>
    <item row="1" column="1">
    <widget class="QDialogButtonBox" name="buttonBox">
    <property name="orientation">
    <enum>Qt::Horizontal</enum>
    </property>
    <property name="standardButtons">
    <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
    </property>
    </widget>
    </item>
    <item row="1" column="2">
    <spacer name="horizontalSpacer">
    <property name="orientation">
    <enum>Qt::Horizontal</enum>
    </property>
    <property name="sizeHint" stdset="0">
    <size>
    <width>65</width>
    <height>20</height>
    </size>
    </property>
    </spacer>
    </item>
    </layout>
    </widget>
    <resources/>
    <connections>
    <connection>
    <sender>buttonBox</sender>
    <signal>accepted()</signal>
    <receiver>Dialog</receiver>
    <slot>accept()</slot>
    <hints>
    <hint type="sourcelabel">
    <x>248</x>
    <y>254</y>
    </hint>
    <hint type="destinationlabel">
    <x>157</x>
    <y>274</y>
    </hint>
    </hints>
    </connection>
    <connection>
    <sender>buttonBox</sender>
    <signal>rejected()</signal>
    <receiver>Dialog</receiver>
    <slot>reject()</slot>
    <hints>
    <hint type="sourcelabel">
    <x>316</x>
    <y>260</y>
    </hint>
    <hint type="destinationlabel">
    <x>286</x>
    <y>274</y>
    </hint>
    </hints>
    </connection>
    </connections>
    </ui>
    "
    Designer: An error has occurred while reading the UI file at line 1, column 0: Premature end of document.
    "Phonon::SeekSlider" @


  • Lifetime Qt Champion

    Really strange...

    Could you try to run the Calculator builder example ? To see if it also has the same problem



  • I have tried calculator builder and text finder examples they are working fine


  • Lifetime Qt Champion

    Then copy the ui file from the example in your project and try to load to see if it works also there



  • @"<ui version="4.0" >
    <author></author>
    <comment></comment>
    <exportmacro></exportmacro>
    <class>CalculatorForm</class>
    <widget class="QWidget" name="CalculatorForm" >
    <property name="objectName" >
    <string notr="true" >CalculatorForm</string>
    </property>
    <property name="geometry" >
    <rect>
    <x>0</x>
    <y>0</y>
    <width>276</width>
    <height>98</height>
    </rect>
    </property>
    <property name="sizePolicy" >
    <sizepolicy>
    <hsizetype>5</hsizetype>
    <vsizetype>5</vsizetype>
    <horstretch>0</horstretch>
    <verstretch>0</verstretch>
    </sizepolicy>
    </property>
    <property name="windowTitle" >
    <string>Calculator Builder</string>
    </property>
    <layout class="QGridLayout" >
    <property name="objectName" >
    <string notr="true" />
    </property>
    <property name="margin" >
    <number>9</number>
    </property>
    <property name="spacing" >
    <number>6</number>
    </property>
    <item row="0" column="0" >
    <layout class="QHBoxLayout" >
    <property name="objectName" >
    <string notr="true" />
    </property>
    <property name="margin" >
    <number>1</number>



  • loading calculator.ui giving the same error in my application


  • Lifetime Qt Champion

    Then can you post your pro file and a minimal code example that reproduce the problem ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.