PDA

View Full Version : Reference to ui



Phalanx
19th April 2010, 19:55
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

Phalanx
19th April 2010, 21:03
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 :confused:

squidge
19th April 2010, 22:34
You do understand that you should never, ever, edit the generated files such as ui_*.h, right?

Phalanx
20th April 2010, 05:00
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;

Lykurg
20th April 2010, 06:51
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...

Phalanx
20th April 2010, 07:16
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);

Phalanx
20th April 2010, 07:44
I have code it by this tutorial (option first): forum_Nokia (http://wiki.forum.nokia.com/index.php/Handling_right_button_clicks_using_Qt)
I need to use ui in class RCQListWidget, please help :(

Phalanx
22nd April 2010, 15:58
Solved. Use first manual but register ui->listWidget->installEventFilter(this); in constructor of up widget