Results 1 to 9 of 9

Thread: How to use two .ui's in a .cpp?

  1. #1
    Join Date
    Dec 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to use two .ui's in a .cpp?

    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
    Last edited by ada; 5th December 2010 at 19:29.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to use two .ui's in a .cpp?

    There are many methods to integrate ui files into C++ code, here 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 (exec() is not valid if you inherit from QWidget or QMainWindow, only if you inherit from QDialog)

  3. #3
    Join Date
    Dec 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to use two .ui's in a .cpp?

    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.

  4. #4
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to use two .ui's in a .cpp?

    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

  5. #5
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to use two .ui's in a .cpp?

    I guess you talk about QTableWidget when you said table, in this case QTableWidget already has the itemDoubleClick(QTableWidgetItem *item) 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.

  6. #6
    Join Date
    Dec 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to use two .ui's in a .cpp?

    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

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to use two .ui's in a .cpp?

    I suggest you read the other thread you have started on this same topic: http://www.qtcentre.org/threads/3663...ht=#post168764

  8. #8
    Join Date
    Dec 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to use two .ui's in a .cpp?

    did it. thanks anyway

  9. #9
    Join Date
    Jan 2011
    Posts
    1

    Default Re: How to use two .ui's in a .cpp?

    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

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.