Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Polish
  4. CheckBox

CheckBox

Scheduled Pinned Locked Moved Polish
2 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dudi
    wrote on last edited by
    #1

    Witam, mam problem z zapisaniem do pliku kilku odpowiedzi z checkBox-a.

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "QMessageBox"
    #include "QFile"
    #include "QTextStream"
    #include "QtGui"
    #include "QtCore"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    }

    MainWindow::~MainWindow()
    {
    delete ui;

    }

    void MainWindow::on_pushButton_2_clicked()

    {
    if (ui->checkBox -> isChecked())
    {

    QFile file("ankiet.txt");
        QString str = "Przegladam strony internetowe   ";
         if(file.open(QIODevice::WriteOnly))
        {
            QTextStream out(&file);
            out.setCodec("UTF-8");
    
            out <<str;
            file.close();
        }
    

    }

    if (ui->checkBox_2 -> isChecked())
    {

    QFile file&#40;"ankiet.txt"&#41;;
        QString str = "Korzystam z poczty elektronicznej ";
         if(file.open(QIODevice::WriteOnly))
        {
            QTextStream out(&file);
            out.setCodec("UTF-8");
    
            out <<str;
            file.close();
        }
    

    }

    if (ui->checkBox_3 -> isChecked())
    {

    QFile file&#40;"ankiet.txt"&#41;;
        QString str = "Przeglądam serwisy informacyjne ";
         if(file.open(QIODevice::WriteOnly))
        {
            QTextStream out(&file);
            out.setCodec("UTF-8");
    
            out <<str;
            file.close();
        }
    

    }
    .
    .
    .
    .
    .

    if (ui->checkBox_10 -> isChecked())
    {

    QFile file&#40;"ankiet.txt"&#41;;
        QString str = "Przeglądam .... ";
         if(file.open(QIODevice::WriteOnly))
        {
            QTextStream out(&file);
            out.setCodec("UTF-8");
    
            out <<str;
            file.close();
        }
    

    }

    dlaczego zapisuje mi tylko jedna odpowiedz albo nie zapisuje i pozostaje stara odpowiedz??

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Domyślny tryb otwierania plików to Truncate. Dodaj QIODevice::Append do flag otwarcia pliku. Przy okazji dobrze jest też dodać QIODevice::Text, wtedy Qt wie lepiej, czego się spodziewać.

      Aha, postując na tym forum, otaczaj kod tagami '@'.

      Przykład otwarcia pliku:
      @
      QFile file(“ankiet.txt”);
      QString str = “Przeglądam …. “;
      if(file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) {
      QTextStream out(&file);
      out.setCodec(“UTF-8”)
      out <<str; file.close();
      }
      @

      (Z(:^

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved