Results 1 to 11 of 11

Thread: [QT] QDialog

  1. #1
    Join Date
    Dec 2010
    Posts
    24
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default [QT] QDialog

    I'm with a doubt stupid, but I could not solve

    I have two windows, a QMainWindow, and another QDialog, see:

    Qt Code:
    1. NSControl::NSControl(QWidget *parent, Qt::WFlags flags)
    2. : QMainWindow(parent, flags)
    3. {
    4. //SETUP OF UI
    5. ui.setupUi(this);
    6.  
    7. //SETUP WINDOW(POPUP)
    8. add = new Add(this);
    9.  
    10. //CONNECTS
    11. connect(ui.actionSair, SIGNAL(triggered()), this, SLOT(close()) );
    12. connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(Apply()) );
    13. connect(ui.actionSobre, SIGNAL(triggered()), this, SLOT(About()) );
    14. connect(ui.actionAdicionar_Endere_o, SIGNAL(triggered()), this, SLOT(AddButton()) );
    15.  
    16. ui.info_tempo->setText("1min");
    17. }
    18.  
    19. NSControl::~NSControl()
    20. {
    21.  
    22. }
    23.  
    24. void NSControl::Apply()
    25. {
    26. QString tempo = ui.comboBox->currentText();
    27.  
    28. ui.info_tempo->setText(tempo);
    29. }
    30.  
    31. void NSControl::About()
    32. {
    33. QMessageBox::about( this, tr("Sobre NSControl"), tr("Desenvolvido por Mateus Vitali") );
    34. }
    35.  
    36. void NSControl::AddButton()
    37. {
    38. add->show();
    39. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. Add::Add(QWidget *parent, Qt::WFlags flags)
    2. {
    3. //SETUP OF UI
    4. ui.setupUi(this);
    5.  
    6. //CONNECTS
    7. connect(ui.cancelar, SIGNAL(triggered()), this, SLOT(Cancel()) );
    8. connect(ui.salvar, SIGNAL(triggered()), this, SLOT(Save()) );
    9. }
    10.  
    11. Add::~Add()
    12. {
    13.  
    14. }
    15.  
    16. void Add::Save()
    17. {
    18. QMessageBox::about( this, tr("Sobre NSControl"), tr("Desenvolvido por Mateus Vitali") );
    19. }
    20.  
    21. void Add::Cancel()
    22. {
    23. QMessageBox::about( this, tr("Sobre NSControl"), tr("Desenvolvido por Mateus Vitali") );
    24. this->hide();
    25. }
    To copy to clipboard, switch view to plain text mode 

    When I click the Add button, it opens the QDialog (add), but when I try to click on the buttons QDialog (Save and Cancel), nothing happens, and one was to appear as I hadplanned QMessageBox

    Why?

  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: [QT] QDialog

    salvar and cancelar i guess are QPushButtons?
    If so they don't have triggered() signal, try clicked()

  3. The following user says thank you to Zlatomir for this useful post:

    zoz (8th February 2011)

  4. #3
    Join Date
    Dec 2010
    Posts
    24
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: [QT] QDialog

    Quote Originally Posted by Zlatomir View Post
    salvar and cancelar i guess are QPushButtons?
    If so they don't have triggered() signal, try clicked()
    Yes, they are QPushButtons!
    Sorry to mix English with my language (Portuguese)

    I swapped triggered () signal by clicked () and worked

    Thanks


    Added after 34 minutes:


    I have another doubt

    I'm trying to create an XML file like this:
    <List>
    <Client_1 E-mail="test@test.com" Phone="1235353" Name="test" IP/DNS="test"/>
    <Client_2 E-mail="test@test.com" Phone="1235353" Name="test" IP/DNS="test"/>
    <Client_3 E-mail="test@test.com" Phone="1235353" Name="test" IP/DNS="test"/>
    <Client_4 E-mail="test@test.com" Phone="1235353" Name="test" IP/DNS="test"/>
    <Client_5 E-mail="test@test.com" Phone="1235353" Name="test" IP/DNS="test"/>
    </List>
    I'm doing well:
    Qt Code:
    1. void Add::Save()
    2. {
    3. QDomDocument doc("List");
    4. QDomElement root = doc.createElement("List");
    5. doc.appendChild(root);
    6.  
    7. QDomElement cn = doc.createElement("Client_1");
    8.  
    9. cn.setAttribute("Phone", ui.phone->text());
    10. cn.setAttribute("E-mail", ui.email->text());
    11. cn.setAttribute("Name", ui.name->text());
    12. cn.setAttribute("IP/DNS", ui.ip->text());
    13.  
    14. root.appendChild(cn);
    15.  
    16. QFile file1("List.xml");
    17. if( !file1.open(QIODevice::Append) ) { }
    18.  
    19. QTextStream ts( &file1 );
    20. ts << doc.toString();
    21.  
    22. file1.close();
    23. }
    To copy to clipboard, switch view to plain text mode 

    But when an information unless I close the program and open again to save another information it looks like this:
    <!DOCTYPE List>
    <Lista>
    <Client_1 E-mail="test@test.com" Phone="1235353" Name="test" IP/DNS="test"/>
    </Lista>
    <!DOCTYPE List>
    <Lista>
    <Client_1 E-mail="" Phone="" Name="333333" IP/DNS=""/>
    </List>
    Last edited by VitaliBR; 1st February 2011 at 22:03.

  5. #4
    Join Date
    Dec 2010
    Posts
    24
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: [QT] QDialog

    anyone?

  6. #5
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [QT] QDialog

    hi if u want to store 5 elements, then u need to loop tat
    Bala

  7. #6
    Join Date
    Dec 2010
    Posts
    24
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: [QT] QDialog

    But I want to do this continuously,
    ie I add two items today, tomorrow another 20, then 1, and so on

  8. #7
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: [QT] QDialog

    hi,
    But I want to do this continuously,
    ie I add two items today, tomorrow another 20, then 1, and so on
    u need set a variable and based on that u need to change the value.

    from where you are generating this records? from db?

    Bala

  9. #8
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [QT] QDialog

    change your xml structure:

    Qt Code:
    1. <List>
    2. <Client ID=1 E-mail="test@test.com" Phone="1235353" Name="test" IP/DNS="test"/>
    3. <Client ID=2 E-mail="test@test.com" Phone="1235353" Name="test" IP/DNS="test"/>
    4. <Client ID=3 E-mail="test@test.com" Phone="1235353" Name="test" IP/DNS="test"/>
    5. <Client ID=4 E-mail="test@test.com" Phone="1235353" Name="test" IP/DNS="test"/>
    6. <Client ID=5 E-mail="test@test.com" Phone="1235353" Name="test" IP/DNS="test"/>
    7. </List>
    To copy to clipboard, switch view to plain text mode 

    then you search for all Nodes "Client" and you can process them in a loop.

  10. #9
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: [QT] QDialog

    Qt Code:
    1. QDomElement root = doc.createElement("List");
    2. //...
    3. //...
    4. QFile file1("List.xml");
    5. if( !file1.open(QIODevice::Append) ) { }
    6.  
    7. QTextStream ts( &file1 );
    To copy to clipboard, switch view to plain text mode 

    You are appending the full xml data (with header ect) to your already existing xml file, so this is exactly what you are gonna get, multiple xml documents in one file.
    This is simple xml, so you'd rather want to convert the xml data from file to data structures in your program (eg. QList<MyDataStruct> data = readDataFromXml("List.xml"), work on those structures ( eg. data.append(new_client); ) and then save it (the whole list: old values + new added in current program session, eg. saveDataToXmlFile(data,"List.xml") ).

    Another probelm is that you are creating a text stream on a file that will eventually fail to open, should be:
    Qt Code:
    1. QFile file1("List.xml");
    2. if( !file1.open(...) ) { return; }
    To copy to clipboard, switch view to plain text mode 

  11. #10
    Join Date
    Dec 2010
    Posts
    24
    Thanks
    4
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: [QT] QDialog

    Thanks for the tip friend
    and then how would my code? Excuse my ignorance

  12. #11
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: [QT] QDialog

    and then how would my code? Excuse my ignorance
    I can only give you some tips. First of all, create a class wrapping the "Client", it should contain all the data that you want to associate with a client, so ( according to your xml file, and applying the improvement from FelixB ) should look like this:
    Qt Code:
    1. class Client{
    2. public:
    3. // ... constructors, member access methods ect
    4. protected:
    5. uint _id;
    6. QString _email;
    7. // ... and other data you want
    8. };
    To copy to clipboard, switch view to plain text mode 

    When saving to xml you can iterate over a list of object of class Client:
    Qt Code:
    1. foreach( const Client& client, _clientsData ){
    2. QDomElement cn = doc.createElement("Client");
    3. cn.setAttribute("ID", client.id());
    4. // .. and so on
    5. }
    To copy to clipboard, switch view to plain text mode 

    Method that loads xml could return a QList of Clients (implement it yourself)
    I'll leave up to you what is and where should be "_clientsData", Client class implementation and other methods ect..
    Again, I wont give full code ( I doubt that anyone will ), you'll learn much more implementing this yourself.

  13. The following user says thank you to stampede for this useful post:

    zoz (8th February 2011)

Similar Threads

  1. QDialog
    By jayreddy in forum Qt Programming
    Replies: 5
    Last Post: 29th December 2009, 09:51
  2. closing a Qdialog called from a Qdialog
    By OverTheOCean in forum Qt Programming
    Replies: 3
    Last Post: 28th September 2009, 08:02
  3. QDialog in DLL
    By markvi in forum Qt Programming
    Replies: 0
    Last Post: 16th September 2009, 10:31
  4. How to "lock" a new qdialog in another qdialog
    By donglebob in forum Qt Programming
    Replies: 7
    Last Post: 4th February 2009, 08:37
  5. QDialog ?
    By allensr in forum Qt Programming
    Replies: 7
    Last Post: 28th November 2007, 19:35

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.