PDA

View Full Version : How to use two .ui's in a .cpp?



ada
5th December 2010, 20:29
Hi,
I have a mainwindow.ui and its .h and .cpp's. I added another .ui named personelInfo.ui but there is no .h or .cpp files of it. How can I reach it with mainwindow.cpp? I use ui->... but it only gets mainwindow.ui, how do I use personelInfo.ui's ui in this? Do I define it in mainwindow.h? How do I do it? I don't get c++ much.

Added after 43 minutes:

Could you please help me I don't know how to do this

Zlatomir
5th December 2010, 20:40
There are many methods to integrate ui files into C++ code, here (http://doc.qt.nokia.com/4.7/designer-using-a-ui-file.html) is the documentation.

And after you can create object of your type (the one that enclosure the .ui file) you can use it whenever you like, for example to open when you click a pushButton, something like here (http://www.qtcentre.org/faq.php?faq=qt_general_category#faq_qt_designer_2f orms) (exec() is not valid if you inherit from QWidget or QMainWindow, only if you inherit from QDialog)

ada
5th December 2010, 21:13
thank you I did it by making the other class' ui by public. I have one other question though. For example, I want to double click an item in the table and I will show that item's data in the other form. I guess itemDoubleClicked passes two values, row and column number. How do I get them? I made the signals on the designer therefore I don't know how to do that.

marcvanriet
5th December 2010, 21:17
Hi,

I guess you are using QtCreator (otherwise I would advise you to do so) and that you created the ui in File - New file or class - Qt - Qt Designer Form ? Next time, use File - New file or class - Qt - Qt Designer Form Class. Then you get the .cpp and .h files as well.

It is best to use a separate .cpp/.h file for each different form.

If you have troubles opening the second form, then see the FAQ in Zlatomir's post. There are also a lot of forum questions and answers about opening a separate form which you can search for.

As a sidenote, you really really should learn C++ if you want to use Qt. Or use another language like Python (using PyQt) that may be easier to use and/or learn.

Best regards,
Marc

Zlatomir
5th December 2010, 21:42
I guess you talk about QTableWidget (http://doc.trolltech.com/4.7/qtablewidget.html) when you said table, in this case QTableWidget already has the itemDoubleClick(QTableWidgetItem *item) (http://doc.trolltech.com/4.7/qtablewidget.html#itemDoubleClicked) signal, so you will only need to create a slot (to connect with the signal) that take a QTableWidgetItem pointer and then create a dialog to display the data that item points to (maybe your second form, depends on the design of your application)

Either way you are going to need to write code, i see you try to run away from code, it has been said before: if you are not comfortable with C++, you need to learn that, and after that learn Qt.

ada
5th December 2010, 21:43
Hi,
I did it already and I can open a new form etc. I also created a frame and I wanted to replace it with another frame in the other form but as I see when I use frameSth.show() it opens it in a new window. That s my main problem now :)

ChrisW67
5th December 2010, 22:14
I suggest you read the other thread you have started on this same topic: http://www.qtcentre.org/threads/36631-How-to-change-only-part-of-an-application-with-signals-button-clicked?p=168764&highlight=#post168764

ada
5th December 2010, 23:24
did it. thanks anyway

macin
8th January 2011, 18:00
Hi, how did you manage to do it? It would be helpful if you could post the answer for this "simple" question, which obviously is not that simple for beginners