Results 1 to 9 of 9

Thread: How to initiate a form based on QUiLoader

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to initiate a form based on QUiLoader

    As I see it, all needed widgets are created on the heap, only the builder is created on the stack. Which is fine.
    But are you sure the path to the ui file is correct? I don't think so. Debug what
    Qt Code:
    1. file.open(QFile::ReadOnly);
    To copy to clipboard, switch view to plain text mode 
    says. Remember the relative path is relativ to the executable directory.

  2. #2
    Join Date
    Mar 2008
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to initiate a form based on QUiLoader

    Hi Lykurg, thanks for your advice. qDebug returned true for that line though I looked at the code more closely around there afterwards. The examples all show the use of:
    Qt Code:
    1. QFile file(":form.ui");
    To copy to clipboard, switch view to plain text mode 
    where as I had:
    Qt Code:
    1. QFile file("form.ui");
    To copy to clipboard, switch view to plain text mode 

    Anyway, I changed my code to match the format of :form.ui and I am now getting the following error:
    Designer: An error has occurred while reading the UI file at line 1, column 0: Premature end of document.
    QLayout: Cannot add null widget to QVBoxLayout/
    I have now tried several different .ui files but all provide the same error. Do you have any suggestions?

    Many thanks.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to initiate a form based on QUiLoader

    Hi,

    the ":" only indicates that it uses the resource system of Qt. You don't need that. Also your two line about tmpButton are nonsense. Anyway, I can't see a real problem in your code. Although you are mixing two approaches on how to use ui files when you also declare a ui pointer in the header file. (See the Qt Designer manual for a detailed description on how to use ui files)

    But to the problem: what does
    Qt Code:
    1. qWarning() << file.readAll();
    To copy to clipboard, switch view to plain text mode 
    say? (after opening it off course) It must be something with the file. It isn't read correctly...

  4. #4
    Join Date
    Mar 2008
    Posts
    12
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to initiate a form based on QUiLoader

    Hi, I tried to use the qWarning() function but just had:
    ""
    printed each time on the console.

    Could my problem be caused because I am trying to call the UI from a button click within an existing QWindow. I have got the code to load the form in the end by changing the following:

    Qt Code:
    1. QUiLoader builder;
    2. QFile file("form.ui");
    3. file.open(QFile::ReadOnly);
    4. QWidget *myWidget = builder.load(&file, this);
    5. QVBoxLayout *layout = new QVBoxLayout;
    6. layout->addWidget(myWidget);
    7. setLayout(layout);
    To copy to clipboard, switch view to plain text mode 

    to

    Qt Code:
    1. QUiLoader builder;
    2. QFile file("../form.ui");
    3. file.open(QFile::ReadOnly);
    4. QWidget *myWidget = builder.load(&file);
    5. myWidget->show();
    6. file.close();
    To copy to clipboard, switch view to plain text mode 

    Is there anything wrong with the new code or can I settle on it?

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to initiate a form based on QUiLoader

    Quote Originally Posted by peterjb31 View Post
    Hi, I tried to use the qWarning() function but just had:
    Yes, that is what I said in post #5: Your file is not loaded. Why: because you are using a relative path.
    So: use the resource system or use an absolute path or use a correct relative path. (See also [WIKI]Current working directory[/WIKI])

  6. The following 2 users say thank you to Lykurg for this useful post:

    Niamita (4th October 2011), peterjb31 (7th April 2011)

Similar Threads

  1. undefined reference to `QUiLoader::QUiLoader(QObject*)'
    By ashukla in forum Qt Programming
    Replies: 7
    Last Post: 7th October 2011, 18:05
  2. Replies: 0
    Last Post: 31st July 2010, 17:27
  3. Advanced use of QUiLoader
    By doberkofler in forum Qt Programming
    Replies: 2
    Last Post: 28th October 2009, 15:47
  4. Advanced use of QUiLoader
    By doberkofler in forum Newbie
    Replies: 0
    Last Post: 27th October 2009, 21:02
  5. Initiate file download on drag from between models
    By psih128 in forum Qt Programming
    Replies: 2
    Last Post: 15th March 2009, 21:03

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
  •  
Qt is a trademark of The Qt Company.