Results 1 to 8 of 8

Thread: why the command endl; dont work in my code ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2017
    Posts
    8
    Qt products
    Qt3 Qt5
    Platforms
    Windows

    Default why the command endl; dont work in my code ?

    Good morninng every body! I dont understand why the command "endl;" in the code below dont make the cursor of the file "out.txt" go to the next line when writing in it. My APPICLATION consist of ask names of students and their notes to write all of that in the file "out.txt by clicking on the button "genere notes ". The command "endl;" is implemeted in the slot "genereNotes" as in the code below:
    This is the header:
    Qt Code:
    1. #ifndef TEST2_H
    2. #define TEST2_H
    3. #include <QObject>
    4. #include <QApplication>
    5. #include <QWidget>
    6. #include <QBoxLayout>
    7. #include <QGridLayout>
    8. #include <QDoubleSpinBox>
    9. #include <QLabel>
    10. #include <QInputDialog>
    11. #include <QString>
    12. #include <QIcon>
    13. #include <QTextEdit>
    14. #include <QPushButton>
    15. #include <QFile>
    16. #include <QTextStream>
    17. #include <QMessageBox>
    18. #include <QFormLayout>
    19. #include <QHBoxLayout>
    20. #include <QVBoxLayout>
    21.  
    22. class MaFenetre : public QWidget
    23. {
    24. Q_OBJECT
    25. public:
    26. MaFenetre();
    27. ~MaFenetre();
    28. public slots:
    29. void genereNotes();
    30. private:
    31. QString liste1;
    32. QString liste2;
    33. QString liste3;
    34. QString liste4;
    35. QString liste5;
    36. QString liste6;
    37. QFormLayout* layout1;
    38. QFormLayout* layout2;
    39. QFormLayout* layout3;
    40. QFormLayout* layout4;
    41. QFormLayout* layout5;
    42. QFormLayout* layout6;
    43.  
    44.  
    45. };
    46.  
    47.  
    48. #endif // TEST2_H
    To copy to clipboard, switch view to plain text mode 

    This the cpp where the slot is implemented:
    Qt Code:
    1. #include "test2.h"
    2. MaFenetre::MaFenetre():QWidget(),liste1("nom"),liste2("nom"),liste3("nom"),liste4("nom"),liste5("nom"),liste6("nom")
    3. {
    4. note1=new QDoubleSpinBox ;
    5. note2=new QDoubleSpinBox ;
    6. note3=new QDoubleSpinBox ;
    7. note4=new QDoubleSpinBox ;
    8. note5=new QDoubleSpinBox ;
    9. note6=new QDoubleSpinBox ;
    10. layout1=new QFormLayout;
    11. layout2=new QFormLayout;
    12. layout3=new QFormLayout;
    13. layout4=new QFormLayout;
    14. layout5=new QFormLayout;
    15. layout6=new QFormLayout;
    16. QVBoxLayout *vlayout=new QVBoxLayout;
    17. QPushButton *button=new QPushButton("generer note",this);
    18. QString eleve;
    19. bool ok(false);
    20. do{eleve=QInputDialog::getText(this,
    21. "Question","Saisissez le nom de l'eleve",QLineEdit::Normal,QString(),&ok);liste1=eleve;}
    22. while(!ok||eleve.isEmpty());
    23. do{eleve=QInputDialog::getText(this,
    24. "Question","Saisissez le nom de l'eleve",QLineEdit::Normal,QString(),&ok);liste2=eleve;}
    25. while(!ok||eleve.isEmpty());
    26. do{eleve=QInputDialog::getText(this,
    27. "Question","Saisissez le nom de l'eleve",QLineEdit::Normal,QString(),&ok);liste3=eleve;}
    28. while(!ok||eleve.isEmpty());
    29. do{eleve=QInputDialog::getText(this,
    30. "Question","Saisissez le nom de l'eleve",QLineEdit::Normal,QString(),&ok);liste4=eleve;}
    31. while(!ok||eleve.isEmpty());
    32. do{eleve=QInputDialog::getText(this,
    33. "Question","Saisissez le nom de l'eleve",QLineEdit::Normal,QString(),&ok);liste5=eleve;}
    34. while(!ok||eleve.isEmpty());
    35. do{eleve=QInputDialog::getText(this,
    36. "Question","Saisissez le nom de l'eleve",QLineEdit::Normal,QString(),&ok);liste6=eleve;}
    37. while(!ok||eleve.isEmpty());
    38.  
    39.  
    40. layout1->addRow(liste1,note1);
    41. layout2->addRow(liste2,note2);
    42. layout3->addRow(liste3,note3);
    43. layout4->addRow(liste4,note4);
    44. layout5->addRow(liste5,note5);
    45. layout6->addRow(liste6,note6);
    46.  
    47. vlayout->addLayout(layout1);
    48. vlayout->addLayout(layout2);
    49. vlayout->addLayout(layout3);
    50. vlayout->addLayout(layout4);
    51. vlayout->addLayout(layout5);
    52. vlayout->addLayout(layout6);
    53. vlayout->addWidget(button);
    54. this->setLayout(vlayout);
    55. QObject::connect(button,SIGNAL(clicked()),this,SLOT(genereNotes()));
    56.  
    57. }
    58. MaFenetre::~MaFenetre()
    59. {
    60.  
    61. }
    62.  
    63. void MaFenetre::genereNotes()
    64. { int i(0);
    65. QFile file("out.txt");
    66. if(file.exists()&&file.open(QIODevice::WriteOnly)){QMessageBox::information(this,"A propos du bulletin","Ouverture réussie de "+file.fileName());
    67. QTextStream out(&file);
    68. out<<liste1;for(i=0;i<10-liste1.size();i++)
    69. {
    70. out<<" ";
    71. }
    72. out<<note1->value()<<"\n";out<<liste2;for(i=0;i<10-liste2.size();i++)
    73. {
    74. out<<" ";
    75. }
    76. out<<note2->value()<< endl;out<<liste3;for(i=0;i<10-liste3.size();i++)
    77. {
    78. out<<" ";
    79.  
    80. }out<<note3->value()<< endl;out<<liste4;for(i=0;i<10-liste4.size();i++)
    81. {
    82. out<<" ";
    83. }
    84. out<<note4->value()<< endl;out<<liste5;for(i=0;i<10-liste5.size();i++)
    85. {
    86. out<<" ";
    87. }
    88. out<<note5->value()<< endl;out<<liste6;for(i=0;i<10-liste6.size();i++)
    89. {
    90. out<<" ";
    91. }
    92. out<<note6->value()<< endl;
    93. }
    94.  
    95. }
    To copy to clipboard, switch view to plain text mode 

    And there is the main.cpp
    Qt Code:
    1. #include "test2.h"
    2.  
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. MaFenetre fenetre;
    8. fenetre.show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    Please help me!!!!!!!!!!!!
    Last edited by joovoo; 26th June 2017 at 17:20.

Similar Threads

  1. SequentialAnimation dont work - why?!?
    By Szyk in forum Qt Quick
    Replies: 12
    Last Post: 10th December 2016, 12:36
  2. QGesture dont work
    By Talei in forum Qt Programming
    Replies: 0
    Last Post: 21st December 2013, 17:55
  3. QWidget -> updateGeometry dont work.
    By patrik08 in forum Qt Programming
    Replies: 7
    Last Post: 22nd May 2013, 15:55
  4. Replies: 3
    Last Post: 9th October 2012, 02:12
  5. Why this doesn't work? qDebug() << "Test" << std::endl;
    By grayfox in forum Qt Programming
    Replies: 4
    Last Post: 1st June 2011, 10:19

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.