Results 1 to 8 of 8

Thread: Reference to ui

  1. #1
    Join Date
    Apr 2010
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Reference to ui

    Hi, I have a widget named FileWidget where is listWidget and fileViewer. I must promote listWidget to capturing right click mouse so now it is a class. constructor is explicit myListWidget(...);

    I add to .h file:

    namespace Ui
    {
    class myListWidgetClass;
    }

    and to costructor
    Ui::myListWidgetClass *ui;

    to *.cpp file add:
    myListWidget::myListWidget(QWidget *parent, TableWidget *ref_TableWidget) :
    QListWidget(parent), ui(new Ui::myListWidgetClass)
    {
    ui->setupUi(this);
    }

    but now it prints invalid use of incomplete type myListWidgetClass and forward declaration of it.
    I don't know how to give a reference to ui.
    (I think my code is right, bud I need to add something elsewhere where I call constructor of that)

    thank you for replies

  2. #2
    Join Date
    Apr 2010
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reference to ui

    I have an error in ui file, reference on not existed file. Now it types me this ui_filewidget.h:34: error: ISO C++ forbids declaration of 'myListWidget' with no type
    Last edited by Phalanx; 19th April 2010 at 21:26.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Reference to ui

    You do understand that you should never, ever, edit the generated files such as ui_*.h, right?

  4. #4
    Join Date
    Apr 2010
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reference to ui

    Sure, but I try that. I delete it then and generated new, it is not a problem.

    Problem is how to give an ui to my promoted QListWidget. I cannot use Ui::myListWidgetClass *ui in here. I dont know how to write it. It would be great if I get ui from constructor

    class myListWidget : public QListWidget
    {
    Q_OBJECT
    public:
    explicit myListWidget(QWidget *parent = 0, TableWidget *ref_TableWidget = 0);
    Ui::myListWidgetClass *ui;
    Last edited by Phalanx; 20th April 2010 at 06:03.

  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: Reference to ui

    Well you can't design a QListWidget alone in designer. So I guess the QListWidget is in a mainwindow and you want to be able to access other elements like buttons from your subclassed QListWidget. If so, just pass a pointer from the main windows to your subclass. But better is to use signals and slots. Your case is exactly why they exists...

  6. #6
    Join Date
    Apr 2010
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reference to ui

    I know what you mean, it would be great if I can use code example. But I haven't got an ui pointer because I have promoted QListWidget to myListWidget

    action_New = new QAction("&New", ui->treeWidget);
    action_Open = new QAction("&Open", ui->treeWidget);

    //add the code at slots
    connect(action_New, SIGNAL(triggered()), this, SLOT(on_action_New_triggered()));
    connect(action_Open, SIGNAL(triggered()), this, SLOT(on_action_Open_triggered()));

    ui->treeWidget->addAction(action_New);
    ui->treeWidget->addAction(action_Open);
    ui->treeWidget->setContextMenuPolicy(Qt::ActionsContextMenu);

  7. #7
    Join Date
    Apr 2010
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reference to ui

    I have code it by this tutorial (option first): forum_Nokia
    I need to use ui in class RCQListWidget, please help

  8. #8
    Join Date
    Apr 2010
    Posts
    21
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Reference to ui

    Solved. Use first manual but register ui->listWidget->installEventFilter(this); in constructor of up widget

Similar Threads

  1. Undefined reference to crt
    By derektaprell in forum Installation and Deployment
    Replies: 0
    Last Post: 20th October 2009, 08:34
  2. Undefined Reference To...
    By ManuMies in forum Qt Programming
    Replies: 6
    Last Post: 10th February 2009, 12:14
  3. Pass by reference
    By vermarajeev in forum General Programming
    Replies: 6
    Last Post: 20th July 2007, 14:53
  4. Undefined reference
    By Salazaar in forum Newbie
    Replies: 12
    Last Post: 23rd May 2007, 10:21
  5. Reference QTableWidgetItem
    By regenbiegen in forum Qt Programming
    Replies: 2
    Last Post: 1st February 2007, 11:34

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.