Autor Tema: Video Tutorial Programación Qt C++  (Leído 38355 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado bigluis

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 511
    • Tutoriales de Qt C++
Re: Video Tutorial Programación Qt C++
« Respuesta #30 en: 10 de Marzo de 2013, 20:53:18 »
Claro que si, el codigo fuente esta en la pagina web que puse arriba en la carpeta que dice "src"

Simplemente tienen que descargar el codigo fuente, reconfigurar para windows y compilarlo
Tutoriales de Qt C++

No es necesario que hagamos Grandes cosas, sino que lo que hagamos sea importante.

SI la NECESIDAD es la MADRE del CONOCIMIENTO, SEGURAMENTE la PEREZA su TÍA.

Cuando el ARTE requiere de PRECISION le llamamos CIENCIA

Desconectado bigluis

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 511
    • Tutoriales de Qt C++
Re: Video Tutorial Programación Qt C++
« Respuesta #31 en: 14 de Marzo de 2013, 17:56:17 »
Hola a todos ahora el video de jQHEditor ya tiene sonido
Tutoriales de Qt C++

No es necesario que hagamos Grandes cosas, sino que lo que hagamos sea importante.

SI la NECESIDAD es la MADRE del CONOCIMIENTO, SEGURAMENTE la PEREZA su TÍA.

Cuando el ARTE requiere de PRECISION le llamamos CIENCIA

Desconectado CompSystems

  • PIC18
  • ****
  • Mensajes: 488
    • Home Page
Re: Video Tutorial Programación Qt C++
« Respuesta #32 en: 04 de Mayo de 2013, 14:36:57 »
Vídeos lanzados recientemente. Creación de un Text Editor,  8 Vídeos  

Gracias por los videotutos, que dominio de bigluis explicando QT! ((:-))

Vídeo 04.01 Crear Menus sobre el - TextEditor - Qt C++

Vídeo 04.02 Editar Menu Save As - TextEditor - Qt C++

Vídeo 04.03 Save and Open File - TextEditor - Qt C++

Vídeo 04.04 New File - TextEditor - Qt C++ (No permite ver en calidad HD)  :(

Vídeo 04.05 Placeholder - TextEditor - Qt C++ (No permite ver en calidad HD)  :(

Vídeo 04.06 Actions Toolbar- TextEditor - Qt C++

Vídeo 04.07  QSettings - TextEditor - Qt C++

Vídeo  04.08 Menu Open Recent Files - TextEditor - Qt C++


En los próximos vídeos me gustaría ver por ejemplo, buscar palabras dentro del texto, Reemplazar, etc


http://www.youtube.com/user/Nicatronica/videos

Ademas hay una nueva version de QT 5.0.2 de 650 MBytes pero la version 5.0.1 tenia 840Mytes. Por que un menor tamaño?
http://qt-project.org/downloads  :-/
« Última modificación: 05 de Mayo de 2013, 10:49:27 por CompSystems »
Desde Colombia

Desconectado CompSystems

  • PIC18
  • ****
  • Mensajes: 488
    • Home Page
Re: Video Tutorial Programación Qt C++
« Respuesta #33 en: 04 de Mayo de 2013, 20:12:36 »
Vídeo 04.02: Incorpora las funciones Guardar  Como en el proyecto de "EDITOR de TEXTO"

04.02 Editar Menu Save As - TextEditor - Qt C++

Código fuente hasta el vídeo 04.02:

Codigo main.cpp

Código: C++
  1. #include "texteditor.h"
  2. #include <QApplication>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6.     QApplication a(argc, argv);
  7.     TextEditor w;
  8.     w.show();
  9.    
  10.     return a.exec();
  11. }

Codigo texteditor.h

Código: C++
  1. #ifndef TEXTEDITOR_H
  2. #define TEXTEDITOR_H
  3.  
  4. #include <QMainWindow>
  5.  
  6. namespace Ui {
  7. class TextEditor;
  8. }
  9.  
  10. class TextEditor : public QMainWindow
  11. {
  12.     Q_OBJECT
  13.    
  14. public:
  15.     explicit TextEditor(QWidget *parent = 0);
  16.     ~TextEditor();
  17.    
  18. private slots:
  19.     void on_action_Save_As_triggered();
  20.  
  21. private:
  22.     Ui::TextEditor *ui;
  23.     void saveFile(); // Funcion para SaveFile con Alt+Enter se agrega definicion en texteditor.cpp
  24.     QString currentFile; // Variable global
  25. };
  26.  
  27. #endif // TEXTEDITOR_H

Codigo texteditor.cpp
Código: C++
  1. #include "texteditor.h"
  2. #include "ui_texteditor.h"
  3. #include <QMessageBox>
  4. #include <QFileDialog>
  5. #include <QDebug>
  6.  
  7. TextEditor::TextEditor(QWidget *parent) :
  8.     QMainWindow(parent),
  9.     ui(new Ui::TextEditor)
  10. {
  11.     ui->setupUi(this);
  12. }
  13.  
  14. TextEditor::~TextEditor()
  15. {
  16.     delete ui;
  17. }
  18.  
  19. void TextEditor::on_action_Save_As_triggered()
  20. {
  21.     QString fileName = QFileDialog::getSaveFileName(
  22.         this,
  23.         "Text Editor - Save As",
  24.         "/Users/Jaime/Documents/QT/Text Editor",
  25.         "Text Files (*.txt);All Files (*.*)"
  26.     );
  27.  
  28.     if ( !fileName.isEmpty() ){ // Si no esta vacio el campo del texto
  29.         currentFile = fileName;
  30.         saveFile();
  31.     }
  32. }
  33.  
  34. void TextEditor::saveFile()
  35. {
  36.     QFile file( currentFile );
  37.     if( file.open ( QFile::WriteOnly ) ){ //  Si se puede abrir el archivo en modo escritura
  38.         file.write( ui->plainTextEdit->toPlainText().toUtf8() );
  39.  
  40.     }else{
  41.         QMessageBox::warning(
  42.             this,
  43.             "Text Editor",
  44.             tr( "Cannot write file %1\nError: %2" )
  45.             .arg( currentFile )
  46.             .arg( file.errorString() )
  47.         );
  48.     }
  49.  
  50. }
« Última modificación: 06 de Mayo de 2013, 14:49:55 por CompSystems »
Desde Colombia

Desconectado Rseliman

  • PIC16
  • ***
  • Mensajes: 239
Re: Video Tutorial Programación Qt C++
« Respuesta #34 en: 05 de Mayo de 2013, 09:58:13 »
Excelente Muchas gracias por compartirlo y traducido !!!!! GRACIAS !!! ((:-)) ((:-)) ((:-))
Las Grandes Obras las sueñan los grandes locos , mientras los inutiles las critican !!

Desconectado CompSystems

  • PIC18
  • ****
  • Mensajes: 488
    • Home Page
Re: Video Tutorial Programación Qt C++
« Respuesta #35 en: 05 de Mayo de 2013, 13:03:06 »
Vídeo 04.03: Incorpora las funciones Guardar y Abrir Archivo en el proyecto de "EDITOR de TEXTO"


04.03 Save and Open File - TextEditor - Qt C++

Tengo un problema al abrir un archivo, en el campo de filtros de archivos aparece los siguiente cadena "xt);;All Files (*.*)",  que estoy codificando mal en on_action_Open_triggered()?
Gracias

Código fuente hasta el vídeo 04.03:

texteditor.cpp
Código: C++
  1. #include "texteditor.h"
  2. #include "ui_texteditor.h"
  3. #include <QMessageBox>
  4. #include <QFileDialog>
  5. #include <QDebug>
  6.  
  7. TextEditor::TextEditor(QWidget *parent) :
  8.     QMainWindow(parent),
  9.     ui(new Ui::TextEditor)
  10. {
  11.     ui->setupUi(this);
  12. }
  13.  
  14. TextEditor::~TextEditor()
  15. {
  16.     delete ui;
  17. }
  18.  
  19. bool TextEditor::on_action_Save_As_triggered()
  20. {
  21.     QString fileName = QFileDialog::getSaveFileName(
  22.         this,
  23.         "Text Editor - Save As",
  24.         "/Users/Jaime/Documents/QT/Text Editor",
  25.         "Text Files (*.txt);;All Files (*.*)"
  26.     );
  27.  
  28.     if ( !fileName.isEmpty() ){ // Si no esta vacio el campo del texto
  29.         currentFile = fileName;
  30.         return saveFile();
  31.     }
  32.     return false;
  33. }
  34.  
  35. bool TextEditor::saveFile()
  36. {
  37.     QFile file( currentFile );
  38.     if( file.open ( QFile::WriteOnly ) ){ //  Si se puede abrir el archivo en modo escritura
  39.         file.write( ui->plainTextEdit->toPlainText().toUtf8() );
  40.         return true;
  41.     }else{
  42.         QMessageBox::warning(
  43.             this,
  44.             "Text Editor",
  45.             tr( "Cannot write file %1.\nError: %2" )
  46.             .arg( currentFile )
  47.             .arg( file.errorString() )
  48.         );
  49.         return false;
  50.     }
  51.  
  52. }
  53.  
  54.  
  55. bool TextEditor::on_action_Save_triggered()
  56. {
  57.     if( currentFile.isEmpty() ) // Si esta vacio
  58.         return on_action_Save_As_triggered();
  59.     else
  60.         return saveFile();
  61. }
  62.  
  63. bool TextEditor::maybeSave(){
  64.     if( ui->plainTextEdit->document()->isModified() ){
  65.         QMessageBox::StandardButton ret =
  66.             QMessageBox::warning(
  67.                 this,
  68.                 "Text Editor",
  69.                 tr( "The Document has been Modified, "
  70.                     "Do you want to save your changes?"
  71.                  ),
  72.                 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel
  73.             );
  74.         if( ret == QMessageBox::Yes ){
  75.            return on_action_Save_triggered();
  76.         }else if( ret == QMessageBox::Cancel )
  77.            return false;
  78.     }
  79.     return true;
  80. }
  81.  
  82. // Filtros "Text Files (*.txt);;All Files (*.*)"
  83. void TextEditor::on_action_Open_triggered()
  84. {
  85.     if( maybeSave() ){
  86.         QString fileName = QFileDialog::getOpenFileName(
  87.             this,
  88.             "Text Editor - Open File"
  89.             "/Users/Jaime/Documents/QT/Text Editor",
  90.             "Text Files (*.txt);;All Files (*.*)"
  91.  
  92.          );
  93.         if ( !fileName.isEmpty() ){ // Si no esta vacio el campo del texto
  94.             QFile file( fileName );
  95.             if ( file.open( QFile::ReadOnly )){ // Se puede leer en modo de lectura
  96.                 ui->plainTextEdit->setPlainText( file.readAll() ); //
  97.                currentFile = fileName;
  98.             }else{
  99.                 QMessageBox::warning(
  100.                     this,
  101.                     "Text Editor",
  102.                     tr( "Cannot read File %1.\nError: %2" )
  103.                     .arg( fileName )
  104.                     .arg( file.errorString() )
  105.                 );
  106.             }
  107.         }
  108.    }
  109. }

texteditor.h
Código: C++
  1. #ifndef TEXTEDITOR_H
  2. #define TEXTEDITOR_H
  3.  
  4. #include <QMainWindow>
  5.  
  6. namespace Ui {
  7. class TextEditor;
  8. }
  9.  
  10. class TextEditor : public QMainWindow
  11. {
  12.     Q_OBJECT
  13.    
  14. public:
  15.     explicit TextEditor(QWidget *parent = 0);
  16.     ~TextEditor();
  17.    
  18. private slots:
  19.     bool on_action_Save_As_triggered();
  20.  
  21.     bool on_action_Save_triggered();
  22.  
  23.     void on_action_Open_triggered();
  24.  
  25. private:
  26.     Ui::TextEditor *ui;
  27.     bool saveFile(); // Funcion para SaveFile con Alt+Enter se agrega definicion en texteditor.cpp
  28.     QString currentFile; // Variable global
  29.     bool maybeSave();
  30. };
  31.  
  32. #endif // TEXTEDITOR_H
« Última modificación: 06 de Mayo de 2013, 14:49:06 por CompSystems »
Desde Colombia

Desconectado CompSystems

  • PIC18
  • ****
  • Mensajes: 488
    • Home Page
Re: Video Tutorial Programación Qt C++
« Respuesta #36 en: 05 de Mayo de 2013, 13:49:01 »
Vídeo 04.04 Incorpora las funciones Nuevo Archivo, Salir, Copiar, Pegar, Cortar en el proyecto de "EDITOR de TEXTO"

04.04 New File - Exit TextEditor - Qt C++


Código fuente hasta el vídeo 04.04:

texteditor.cpp
Código: C++
  1. #include "texteditor.h"
  2. #include "ui_texteditor.h"
  3. #include <QMessageBox>
  4. #include <QFileDialog>
  5. #include <QDebug>
  6.  
  7. TextEditor::TextEditor(QWidget *parent) :
  8.     QMainWindow(parent),
  9.     ui(new Ui::TextEditor)
  10. {
  11.     ui->setupUi(this);
  12. }
  13.  
  14. //TextEditor::~TextEditor()
  15. //{
  16. //    delete ui;
  17. //}
  18.  
  19. bool TextEditor::on_action_Save_As_triggered()
  20. {
  21.     QString fileName = QFileDialog::getSaveFileName(
  22.         this,
  23.         "Text Editor - Save As",
  24.         "/Users/Jaime/Documents/QT/Text Editor",
  25.         "Text Files (*.txt);;All Files (*.*)"
  26.     );
  27.  
  28.     if ( !fileName.isEmpty() ){ // Si no esta vacio el campo del texto
  29.         currentFile = fileName;
  30.         return saveFile();
  31.     }
  32.     return false;
  33. }
  34.  
  35. bool TextEditor::saveFile()
  36. {
  37.     QFile file( currentFile );
  38.     if( file.open ( QFile::WriteOnly ) ){ //  Si se puede abrir el archivo en modo escritura
  39.         file.write( ui->plainTextEdit->toPlainText().toUtf8() );
  40.         return true;
  41.     }else{
  42.         QMessageBox::warning(
  43.             this,
  44.             "Text Editor",
  45.             tr( "Cannot write file %1.\nError: %2" )
  46.             .arg( currentFile )
  47.             .arg( file.errorString() )
  48.         );
  49.         return false;
  50.     }
  51.  
  52. }
  53.  
  54.  
  55. bool TextEditor::on_action_Save_triggered()
  56. {
  57.     if( currentFile.isEmpty() ) // Si esta vacio
  58.         return on_action_Save_As_triggered();
  59.     else
  60.         return saveFile();
  61. }
  62.  
  63. bool TextEditor::maybeSave(){
  64.     if( ui->plainTextEdit->document()->isModified() ){
  65.         QMessageBox::StandardButton ret =
  66.             QMessageBox::warning(
  67.                 this,
  68.                 "Text Editor",
  69.                 tr( "The Document has been Modified\n"
  70.                     "Do you want to save your changes?"
  71.                  ),
  72.                 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel
  73.             );
  74.         if( ret == QMessageBox::Yes ){
  75.            return on_action_Save_triggered();
  76.         }else if( ret == QMessageBox::Cancel )
  77.            return false;
  78.     }
  79.     return true;
  80. }
  81.  
  82. // Filtros "Text Files (*.txt);;All Files (*.*)"
  83. void TextEditor::on_action_Open_triggered()
  84. {
  85.     if( maybeSave() ){
  86.         QString fileName = QFileDialog::getOpenFileName(
  87.             this,
  88.             "Text Editor - Open File"
  89.             "/Users/Jaime/Documents/QT/Text Editor",
  90.             "Text Files (*.txt);;All Files (*.*)"
  91.  
  92.          );
  93.         if ( !fileName.isEmpty() ){ // Si no esta vacio el campo del texto
  94.             QFile file( fileName );
  95.             if ( file.open( QFile::ReadOnly )){ // Se puede leer en modo de lectura
  96.                 ui->plainTextEdit->setPlainText( file.readAll() ); //
  97.                 currentFile = fileName;
  98.             }else{
  99.                 QMessageBox::warning(
  100.                     this,
  101.                     "Text Editor",
  102.                     tr( "Cannot read File %1.\nError: %2" )
  103.                     .arg( fileName )
  104.                     .arg( file.errorString() )
  105.                 );
  106.             }
  107.         }
  108.    }
  109. }
  110.  
  111. void TextEditor::on_action_New_triggered()
  112. {
  113.     if( maybeSave() ){
  114.         ui->plainTextEdit->clean();
  115.     }
  116. }
  117.  
  118.  
  119. void TextEditor::closeEvent( QCloseEvent *event ){
  120.     if( maybeSave() ){
  121.         event->accept();
  122.     }else
  123.         event->ignore();
  124. }

texteditor.h
Código: C++
  1. #ifndef TEXTEDITOR_H
  2. #define TEXTEDITOR_H
  3.  
  4. #include <QMainWindow>
  5.  
  6. namespace Ui {
  7. class TextEditor;
  8. }
  9.  
  10. class TextEditor : public QMainWindow
  11. {
  12.     Q_OBJECT
  13.    
  14. public:
  15.     explicit TextEditor(QWidget *parent = 0);
  16.     //~TextEditor();
  17.    
  18. private slots:
  19.     bool on_action_Save_As_triggered();
  20.  
  21.     bool on_action_Save_triggered();
  22.  
  23.     void on_action_Open_triggered();
  24.  
  25.     void on_action_New_triggered();
  26.  
  27.     void closeEvent( QCloseEvent *event );
  28.  
  29. private:
  30.     Ui::TextEditor *ui;
  31.     bool saveFile(); // Funcion para SaveFile con Alt+Enter se agrega definicion en texteditor.cpp
  32.     QString currentFile; // Variable global
  33.     bool maybeSave();
  34. };
  35.  
  36. #endif // TEXTEDITOR_H

Nota: Las acciones Salir, Copiar, Pegar, Cortar se ven reflejadas osea codificadas en el archivo "texteditor.ui" y no en texteditor.cpp o texteditor.h
« Última modificación: 06 de Mayo de 2013, 14:48:09 por CompSystems »
Desde Colombia

Desconectado CompSystems

  • PIC18
  • ****
  • Mensajes: 488
    • Home Page
Re: Video Tutorial Programación Qt C++
« Respuesta #37 en: 05 de Mayo de 2013, 21:35:46 »
Vídeo 04.05 Indentificador de modificación de archivo actual, simbolo (*) después del FileName:

04.05 Placeholder [ * ] - TextEditor - Qt C++

Nota: En la version 5.0.2 en Configure Connection aparece como plainTextEdit y según el vídeo se muestra como TextEdit, entonces tuve que editar o cambiar en receiver de plainTextEdit a TextEdit, me escriben si a ustedes les pasa lo mismo

Código fuente hasta el vídeo 04.05:

texteditor.cpp
Código: C++
  1. #include "texteditor.h"
  2. #include "ui_texteditor.h"
  3. #include <QMessageBox>
  4. #include <QFileDialog>
  5. #include <QFileInfo> // Video 04.05
  6. #include <QDebug>
  7.  
  8. TextEditor::TextEditor(QWidget *parent) :
  9.     QMainWindow(parent),
  10.     ui(new Ui::TextEditor)
  11. {
  12.     ui->setupUi(this);
  13. }
  14.  
  15. //TextEditor::~TextEditor()
  16. //{
  17. //    delete ui;
  18. //}
  19.  
  20. bool TextEditor::on_action_Save_As_triggered()
  21. {
  22.     QString fileName = QFileDialog::getSaveFileName(
  23.         this,
  24.         "Text Editor - Save As",
  25.         "/Users/Jaime/Documents/QT/Text Editor",
  26.         "Text Files (*.txt);;All Files (*.*)"
  27.     );
  28.  
  29.     if ( !fileName.isEmpty() ){ // Si no esta vacio el campo del texto
  30.         currentFile = fileName;
  31.         return saveFile();
  32.     }
  33.     return false;
  34. }
  35.  
  36. bool TextEditor::saveFile()
  37. {
  38.     QFile file( currentFile );
  39.     if( file.open ( QFile::WriteOnly ) ){ //  Si se puede abrir el archivo en modo escritura
  40.         file.write( ui->plainTextEdit->toPlainText().toUtf8() );
  41.         setWindowTitle( tr( "Text Editor - %1[*]" ) // Video 04.05
  42.                         .arg( QFileInfo( currentFile ).fileName() ) );
  43.         ui->plainTextEdit->document()->setModified(false); // Video 04.05
  44.         return true;
  45.     }else{
  46.         QMessageBox::warning(
  47.             this,
  48.             "Text Editor",
  49.             tr( "Cannot write file %1.\nError: %2" )
  50.             .arg( currentFile )
  51.             .arg( file.errorString() )
  52.         );
  53.         return false;
  54.     }
  55.  
  56. }
  57.  
  58. bool TextEditor::on_action_Save_triggered()
  59. {
  60.     if( currentFile.isEmpty() ) // Si esta vacio
  61.         return on_action_Save_As_triggered();
  62.     else
  63.         return saveFile();
  64. }
  65.  
  66. bool TextEditor::maybeSave(){
  67.     if( ui->plainTextEdit->document()->isModified() ){
  68.         QMessageBox::StandardButton ret =
  69.             QMessageBox::warning(
  70.                 this,
  71.                 "Text Editor",
  72.                 tr( "The Document has been Modified\n"
  73.                     "Do you want to save your changes?"
  74.                  ),
  75.                 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel
  76.             );
  77.         if( ret == QMessageBox::Yes ){
  78.            return on_action_Save_triggered();
  79.         }else if( ret == QMessageBox::Cancel )
  80.            return false;
  81.     }
  82.     return true;
  83. }
  84.  
  85. // Filtros "Text Files (*.txt);;All Files (*.*)"
  86. void TextEditor::on_action_Open_triggered()
  87. {
  88.     if( maybeSave() ){
  89.         QString fileName = QFileDialog::getOpenFileName(
  90.             this,
  91.             "Text Editor - Open File",
  92.             "/Users/Jaime/Documents/QT/Text Editor",
  93.             "Text Files (*.txt);;All Files (*.*)"
  94.  
  95.          );
  96.         if ( !fileName.isEmpty() ){ // Si no esta vacio el campo del texto
  97.             QFile file( fileName );
  98.             if ( file.open( QFile::ReadOnly )){ // Se puede leer en modo de lectura
  99.                 ui->plainTextEdit->setPlainText( file.readAll() ); //
  100.                 setWindowTitle( tr( "Text Editor - %1[*]" ) // Video 04.05
  101.                                 .arg( QFileInfo( currentFile ).fileName() ) );
  102.                 currentFile = fileName;
  103.             }else{
  104.                 QMessageBox::warning(
  105.                     this,
  106.                     "Text Editor",
  107.                     tr( "Cannot read File %1.\nError: %2" )
  108.                     .arg( fileName )
  109.                     .arg( file.errorString() )
  110.                 );
  111.             }
  112.         }
  113.    }
  114. }
  115.  
  116. void TextEditor::on_action_New_triggered()
  117. {
  118.     if( maybeSave() ){
  119.         ui->plainTextEdit->clear();
  120.     }
  121. }
  122.  
  123.  
  124. void TextEditor::closeEvent( QCloseEvent *event ){
  125.     if( maybeSave() ){
  126.         event->accept();
  127.     }else
  128.         event->ignore();
  129. }
« Última modificación: 07 de Mayo de 2013, 22:34:53 por CompSystems »
Desde Colombia

Desconectado bigluis

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 511
    • Tutoriales de Qt C++
Re: Video Tutorial Programación Qt C++
« Respuesta #38 en: 06 de Mayo de 2013, 00:48:43 »
Hola CompSystems, me parece que no hay nada mal pero por si las dudas abajo del mensaje adjunto el codigo fuente del editor de texto.

PD: Gracias por poner los videos que no habia actualizado en el foro.
Tutoriales de Qt C++

No es necesario que hagamos Grandes cosas, sino que lo que hagamos sea importante.

SI la NECESIDAD es la MADRE del CONOCIMIENTO, SEGURAMENTE la PEREZA su TÍA.

Cuando el ARTE requiere de PRECISION le llamamos CIENCIA

Desconectado CompSystems

  • PIC18
  • ****
  • Mensajes: 488
    • Home Page
Re: Video Tutorial Programación Qt C++
« Respuesta #39 en: 06 de Mayo de 2013, 10:09:14 »
Bigluis Ahora comparo el código que digite con el tuyo. para ver donde esta el problema al ejecutar OPEN  :) , aunque puede ser problema de la ultima version de QT, pues en el video 04.05 encontré una inconsistencia con lo que muestras en el vídeo y que la comento 2 post arriba.

Es posible cambiar el símbolo de * (Archivo modificado) por otra cadena de texto?

Video 04.06 Barra de herramientas con las funciones | New, Open, Save, Save As | Copy, Cut, Paste | ...

Video 04.06 Actions Toolbar- TextEditor - Qt C++

Bigluis por favor podrías guiarme como cambiar el icono al titulo y como agregar un botón en la barra de herramientas que llame a una función de usuario definida en texteditor.cpp

Gracias

« Última modificación: 06 de Mayo de 2013, 14:55:14 por CompSystems »
Desde Colombia

Desconectado CompSystems

  • PIC18
  • ****
  • Mensajes: 488
    • Home Page
Re: Video Tutorial Programación Qt C++
« Respuesta #40 en: 06 de Mayo de 2013, 14:51:50 »
video 04.07 Configuración para guardar la posición y tamaño de la ventana al reiniciar la aplicación


 04.07 QSettings - TextEditor - Qt C++


texteditor.h
Código: C++
  1. #ifndef TEXTEDITOR_H
  2. #define TEXTEDITOR_H
  3.  
  4. #include <QMainWindow>
  5.  
  6. namespace Ui {
  7. class TextEditor;
  8. }
  9.  
  10. class TextEditor : public QMainWindow
  11. {
  12.     Q_OBJECT
  13.    
  14. public:
  15.     explicit TextEditor(QWidget *parent = 0);
  16.     //~TextEditor();
  17.    
  18. private slots:
  19.     bool on_action_Save_As_triggered();
  20.  
  21.     bool on_action_Save_triggered();
  22.  
  23.     void on_action_Open_triggered();
  24.  
  25.     void on_action_New_triggered();
  26.  
  27.     void closeEvent( QCloseEvent *event );
  28.  
  29. private:
  30.     Ui::TextEditor *ui;
  31.     bool saveFile(); // Funcion para SaveFile con Alt+Enter se agrega definicion en texteditor.cpp
  32.     QString currentFile; // Variable global
  33.     bool maybeSave();
  34.     void readSettings();
  35.     void writeSettings();
  36. };
  37.  
  38. #endif // TEXTEDITOR_H

texteditor.cpp
Código: C++
  1. #include "texteditor.h"
  2. #include "ui_texteditor.h"
  3. #include <QMessageBox>
  4. #include <QFileDialog>
  5. #include <QFileInfo> // Video 04.05
  6. #include <QDebug>
  7. #include <QSettings> // Video 04.07
  8.  
  9. TextEditor::TextEditor(QWidget *parent) :
  10.     QMainWindow(parent),
  11.     ui(new Ui::TextEditor)
  12. {
  13.     ui->setupUi(this);
  14.     readSettings(); // Video 04.07
  15. }
  16.  
  17. //TextEditor::~TextEditor()
  18. //{
  19. //    delete ui;
  20. //}
  21.  
  22. bool TextEditor::on_action_Save_As_triggered()
  23. {
  24.     QString fileName = QFileDialog::getSaveFileName(
  25.         this,
  26.         "Text Editor - Save As",
  27.         "/Users/Jaime/Documents/QT/Text Editor",
  28.         "Text Files (*.txt);;All Files (*.*)"
  29.     );
  30.  
  31.     if ( !fileName.isEmpty() ){ // Si no esta vacio el campo del texto
  32.         currentFile = fileName;
  33.         return saveFile();
  34.     }
  35.     return false;
  36. }
  37.  
  38. bool TextEditor::saveFile()
  39. {
  40.     QFile file( currentFile );
  41.     if( file.open ( QFile::WriteOnly ) ){ //  Si se puede abrir el archivo en modo escritura
  42.         file.write( ui->plainTextEdit->toPlainText().toUtf8() );
  43.         setWindowTitle( tr( "Text Editor - %1[*]" ) // Video 04.05
  44.                         .arg( QFileInfo( currentFile ).fileName() ) );
  45.         ui->plainTextEdit->document()->setModified(false); // Video 04.05
  46.         return true;
  47.     }else{
  48.         QMessageBox::warning(
  49.             this,
  50.             "Text Editor",
  51.             tr( "Cannot write file %1.\nError: %2" )
  52.             .arg( currentFile )
  53.             .arg( file.errorString() )
  54.         );
  55.         return false;
  56.     }
  57.  
  58. }
  59.  
  60. bool TextEditor::on_action_Save_triggered()
  61. {
  62.     if( currentFile.isEmpty() ) // Si esta vacio
  63.         return on_action_Save_As_triggered();
  64.     else
  65.         return saveFile();
  66. }
  67.  
  68. bool TextEditor::maybeSave(){
  69.     if( ui->plainTextEdit->document()->isModified() ){
  70.         QMessageBox::StandardButton ret =
  71.             QMessageBox::warning(
  72.                 this,
  73.                 "Text Editor",
  74.                 tr( "The Document has been Modified\n"
  75.                     "Do you want to save your changes?"
  76.                  ),
  77.                 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel
  78.             );
  79.         if( ret == QMessageBox::Yes ){
  80.            return on_action_Save_triggered();
  81.         }else if( ret == QMessageBox::Cancel )
  82.            return false;
  83.     }
  84.     return true;
  85. }
  86.  
  87. void TextEditor::readSettings() // Video 04.07
  88. {
  89.     QSettings settings( "About", "TextEditor" );
  90.     QPoint pos = settings.value( "pos", QPoint( 200, 200 ) ).toPoint();
  91.     QSize size = settings.value( "size", QSize( 400, 400 ) ).toSize();
  92.     resize( size );
  93.     move( pos );
  94. }
  95.  
  96. void TextEditor::writeSettings() // Video 04.07
  97. {
  98.     QSettings settings( "About", "TextEditor" );
  99.     settings.setValue( "pos", pos() );
  100.     settings.setValue( "size", size() );
  101. }
  102.  
  103.  
  104.  
  105. // Filtros "Text Files (*.txt);;All Files (*.*)"
  106. void TextEditor::on_action_Open_triggered()
  107. {
  108.     if( maybeSave() ){
  109.         QString fileName = QFileDialog::getOpenFileName(
  110.             this,
  111.             "Text Editor - Open File",
  112.             "/Users/Jaime/Documents/QT/Text Editor",
  113.             "Text Files (*.txt);;All Files (*.*)"
  114.  
  115.          );
  116.         if ( !fileName.isEmpty() ){ // Si no esta vacio el campo del texto
  117.             QFile file( fileName );
  118.             if ( file.open( QFile::ReadOnly )){ // Se puede leer en modo de lectura
  119.                 ui->plainTextEdit->setPlainText( file.readAll() ); //
  120.                 setWindowTitle( tr( "Text Editor - %1[*]" ) // Video 04.05
  121.                                 .arg( QFileInfo( currentFile ).fileName() ) );
  122.                 currentFile = fileName;
  123.             }else{
  124.                 QMessageBox::warning(
  125.                     this,
  126.                     "Text Editor",
  127.                     tr( "Cannot read File %1.\nError: %2" )
  128.                     .arg( fileName )
  129.                     .arg( file.errorString() )
  130.                 );
  131.             }
  132.         }
  133.    }
  134. }
  135.  
  136. void TextEditor::on_action_New_triggered()
  137. {
  138.     if( maybeSave() ){
  139.         ui->plainTextEdit->clear();
  140.     }
  141. }
  142.  
  143.  
  144. void TextEditor::closeEvent( QCloseEvent *event ){
  145.     if( maybeSave() ){
  146.         writeSettings(); // Video 04.07
  147.         event->accept();
  148.     }else
  149.         event->ignore();
  150. }

La configuración (posición y tamaño) en que archivo del PC queda registrada, para que sea leída al iniciar la aplicación?
« Última modificación: 07 de Mayo de 2013, 22:32:56 por CompSystems »
Desde Colombia

Desconectado CompSystems

  • PIC18
  • ****
  • Mensajes: 488
    • Home Page
Re: Video Tutorial Programación Qt C++
« Respuesta #41 en: 06 de Mayo de 2013, 17:25:46 »
video 04.08 Adherir Archivos recientes en el menú File


texteditor.cpp
Código: C++
  1. #include "texteditor.h"
  2. #include "ui_texteditor.h"
  3. #include <QMessageBox>
  4. #include <QFileDialog>
  5. #include <QFileInfo> // Video 04.05
  6. #include <QDebug>
  7. #include <QSettings> // Video 04.07
  8.  
  9.  
  10.  
  11.  
  12. TextEditor::TextEditor(QWidget *parent) :
  13.     QMainWindow(parent),
  14.     ui(new Ui::TextEditor)
  15. {
  16.     ui->setupUi(this);
  17.     readSettings(); // Video 04.07
  18.  
  19.     for( int i = 0; i < MaxRecentFiles; i++ ){
  20.         recentFilesActs[ i ] = new QAction( this );
  21.         recentFilesActs[ i ]->setVisible( false );
  22.         connect( recentFilesActs[ i ],SIGNAL( triggered() ), this, SLOT( openRecentFile() ));
  23.         ui->Menu_Open_Recent_Files->addAction( recentFilesActs[ i ] );
  24.  
  25.     }
  26.     updateRecentFileActions();
  27. }
  28.  
  29. //TextEditor::~TextEditor()
  30. //{
  31. //    delete ui;
  32. //}
  33.  
  34. bool TextEditor::on_action_Save_As_triggered()
  35. {
  36.     QString fileName = QFileDialog::getSaveFileName(
  37.         this,
  38.         "Text Editor - Save As",
  39.         "/Users/Jaime/Documents/QT/Text Editor/",
  40.         "Text Files (*.txt);;All Files (*.*)"
  41.     );
  42.  
  43.     if ( !fileName.isEmpty() ){ // Si no esta vacio el campo del texto
  44.         currentFile = fileName;
  45.         return saveFile( fileName );
  46.     }
  47.     return false;
  48. }
  49.  
  50. bool TextEditor::saveFile( const QString &fileName )
  51. {
  52.     QFile file( fileName  );
  53.     if( file.open ( QFile::WriteOnly ) ){ //  Si se puede abrir el archivo en modo escritura
  54.         file.write( ui->plainTextEdit->toPlainText().toUtf8() );
  55.         setCurrentFile( fileName );
  56.         setWindowTitle( tr( "Text Editor - %1[*]" ) // Video 04.05
  57.                         .arg( QFileInfo( currentFile ).fileName() ) );
  58.         ui->plainTextEdit->document()->setModified(false); // Video 04.05
  59.         return true;
  60.     }else{
  61.         QMessageBox::warning(
  62.             this,
  63.             "Text Editor",
  64.             tr( "Cannot write file %1.\nError: %2" )
  65.             .arg( currentFile )
  66.             .arg( file.errorString() )
  67.         );
  68.         return false;
  69.     }
  70.  
  71. }
  72.  
  73. bool TextEditor::maybeSave(){
  74.     if( ui->plainTextEdit->document()->isModified() ){
  75.         QMessageBox::StandardButton ret =
  76.             QMessageBox::warning(
  77.                 this,
  78.                 "Text Editor",
  79.                 tr( "The Document has been Modified\n"
  80.                     "Do you want to save your changes?"
  81.                  ),
  82.                 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel
  83.             );
  84.         if( ret == QMessageBox::Yes ){
  85.            return on_action_Save_triggered();
  86.         }else if( ret == QMessageBox::Cancel )
  87.            return false;
  88.     }
  89.     return true;
  90. }
  91.  
  92. void TextEditor::readSettings() // Video 04.07
  93. {
  94.     QSettings settings( "About", "TextEditor" );
  95.     QPoint pos = settings.value( "pos", QPoint( 200, 200 ) ).toPoint();
  96.     QSize size = settings.value( "size", QSize( 400, 400 ) ).toSize();
  97.     resize( size );
  98.     move( pos );
  99. }
  100.  
  101. void TextEditor::writeSettings() // Video 04.07
  102. {
  103.     QSettings settings( "About", "TextEditor" );
  104.     settings.setValue( "pos", pos() );
  105.     settings.setValue( "size", size() );
  106. }
  107.  
  108. void TextEditor::setCurrentFile(const QString &fileName)
  109. {
  110.     currentFile = fileName;
  111.     setWindowTitle( tr( "Text Editor - %1[*]" ) // Video 04.05
  112.                     .arg( QFileInfo( currentFile ).fileName() ) );
  113.     QSettings settings;
  114.     QStringList recentFilesList = settings.value( "recentFilesList" ).toStringList();
  115.     recentFilesList.removeAll( fileName );
  116.     recentFilesList.prepend( fileName );
  117.     while ( recentFilesList.size() > MaxRecentFiles )
  118.         recentFilesList.removeLast();
  119.     settings.setValue( "recentFilesList", recentFilesList );
  120.     updateRecentFileActions();
  121. }
  122.  
  123. bool TextEditor::on_action_Save_triggered()
  124. {
  125.     if( currentFile.isEmpty() ) // Si esta vacio
  126.         return on_action_Save_As_triggered();
  127.     else
  128.         return saveFile( currentFile );
  129. }
  130.  
  131. void TextEditor::on_action_Open_triggered()
  132. {
  133.     if( maybeSave() ){
  134.         QString fileName = QFileDialog::getOpenFileName(
  135.             this,
  136.             "Text Editor - Open File",
  137.             "/Users/Jaime/Documents/QT/Text Editor/",
  138.             "Text Files (*.txt);;All Files (*.*)"
  139.  
  140.          );
  141.      loadFile( fileName );
  142.    }
  143. }
  144.  
  145. void TextEditor::on_action_New_triggered()
  146. {
  147.     if( maybeSave() ){
  148.         ui->plainTextEdit->clear();
  149.     }
  150. }
  151.  
  152. void TextEditor::closeEvent( QCloseEvent *event ){
  153.     if( maybeSave() ){
  154.         writeSettings(); // Video 04.07
  155.         event->accept();
  156.     }else
  157.         event->ignore();
  158. }
  159.  
  160. void TextEditor::openRecentFile()
  161. {
  162.     QAction *action = qobject_cast< QAction *>( sender() );
  163.     if( action ){
  164.         loadFile( action->data().toString() );
  165.     }
  166.  
  167. }
  168.  
  169. void TextEditor::updateRecentFileActions()
  170. {
  171.     QSettings settings;
  172.     QStringList recentFilesList = settings.value( "recentFilesList" ).toStringList();
  173.  
  174.     int numRecentFiles = qMin( recentFilesList.size(), int( MaxRecentFiles ) );
  175.     for( int i = 0; i < numRecentFiles; ++i ){
  176.         QString text = tr( "&%1 %2" )
  177.                 .arg( i+1 )
  178.                 .arg( QFileInfo( recentFilesList[ i ] ).fileName() );
  179.                 recentFilesActs[ i ]->setText( text );
  180.                 recentFilesActs[ i ]->setData( recentFilesList[ i ] );
  181.                 recentFilesActs[ i ]->setVisible( true );
  182.  
  183.     }
  184.     for( int j = numRecentFiles; j > MaxRecentFiles; j++){
  185.         recentFilesActs[ j ]->setVisible( false );
  186.     }
  187.  
  188. }
  189.  
  190. void TextEditor::loadFile(const QString &fileName)
  191. {
  192.     if ( !fileName.isEmpty() ){ // Si no esta vacio el campo del texto
  193.         QFile file( fileName );
  194.         if ( file.open( QFile::ReadOnly )){ // Se puede leer en modo de lectura
  195.             ui->plainTextEdit->setPlainText( file.readAll() ); //
  196.             setCurrentFile( fileName );
  197.         }else{
  198.             QMessageBox::warning(
  199.                 this,
  200.                 "Text Editor",
  201.                 tr( "Cannot read File %1.\nError: %2" )
  202.                 .arg( fileName )
  203.                 .arg( file.errorString() )
  204.             );
  205.         }
  206.     }
  207. }

texteditor.h
Código: C++
  1. #ifndef TEXTEDITOR_H
  2. #define TEXTEDITOR_H
  3.  
  4. #include <QMainWindow>
  5.  
  6. namespace Ui {
  7. class TextEditor;
  8. }
  9.  
  10. class TextEditor : public QMainWindow
  11. {
  12.     Q_OBJECT
  13.    
  14. public:
  15.     explicit TextEditor(QWidget *parent = 0);
  16.     //~TextEditor();
  17.    
  18. private slots:
  19.     bool on_action_Save_As_triggered();
  20.  
  21.     bool on_action_Save_triggered();
  22.  
  23.     void on_action_Open_triggered();
  24.  
  25.     void on_action_New_triggered();
  26.  
  27.     void closeEvent( QCloseEvent *event );
  28.  
  29.     void openRecentFile();
  30.  
  31. private:
  32.     Ui::TextEditor *ui;
  33.     bool saveFile( const QString &fileName ); // Funcion para SaveFile con Alt+Enter se agrega definicion en texteditor.cpp
  34.     bool maybeSave();
  35.     void readSettings();
  36.     void writeSettings();
  37.  
  38.     void setCurrentFile( const QString &fileName );
  39.     void updateRecentFileActions();
  40.     void loadFile( const QString &fileName );
  41.     QString currentFile; // Variable global
  42.  
  43.     enum { MaxRecentFiles = 9 };
  44.     QAction *recentFilesActs[ MaxRecentFiles ];
  45.  
  46.  
  47. };
  48.  
  49. #endif // TEXTEDITOR_H
« Última modificación: 07 de Mayo de 2013, 22:28:11 por CompSystems »
Desde Colombia

Desconectado CompSystems

  • PIC18
  • ****
  • Mensajes: 488
    • Home Page
Re: Video Tutorial Programación Qt C++
« Respuesta #42 en: 07 de Mayo de 2013, 17:14:13 »
Comparando el codigo que yo digite con el de Bigluis,

texteditor.cpp (Bigluis) anexa las siguientes libs, que hace que en mi version de QT 5.0.2 no compile satisfactoriamente  :(
#include <QList>
#include <QtCore>
#include <Qsci/qsciscintilla.h>

La ruta por defecto para guardar los archivos en mi caso es:

"/Users/Jaime/Documents/QT/Text Editor/"

En el de Bigluis
"/home/luis/Documents",

Como se hace para que el programa lea la carpeta MIS DOCUMENTOS (independiente del OS), pero sin escribir el nombre del usuario, por que cuando se ejecuta en otra maquina esta apuntara a otro lugar?


otras diferencias:
En mi caso
file.write( ui->plainTextEdit->toPlainText().toUtf8() );

BigLuis
file.write(ui->plainTextEdit->toPlainText().toLatin1());

Tengo problemas al abrir un archivo, no permite seleccionarlo, no se despliega el menú archivos recientes

Mi codigo fuente:
TextEditor with QT Project
« Última modificación: 08 de Mayo de 2013, 10:53:25 por CompSystems »
Desde Colombia

Desconectado bigluis

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 511
    • Tutoriales de Qt C++
Re: Video Tutorial Programación Qt C++
« Respuesta #43 en: 07 de Mayo de 2013, 18:44:03 »

Tengo un problema al abrir un archivo, en el campo de filtros de archivos aparece los siguiente cadena "xt);;All Files (*.*)",  que estoy codificando mal en on_action_Open_triggered()?

Hola CompSystem, el problema es que te hizo falta una coma en la segunda opcion del openFileName

tu codigo esta asi

Código: C
  1. if( maybeSave() ){
  2.         QString fileName = QFileDialog::getOpenFileName(
  3.             this,
  4.             "Text Editor - Open File"
  5.             "/Users/luis/Documents/QT/Text Editor/",
  6.             "Text Files (*.txt);;All Files (*.*)"
  7.  
  8.          );

y deberia estar asi

Código: C
  1. if( maybeSave() ){
  2.         QString fileName = QFileDialog::getOpenFileName(
  3.             this,
  4.             "Text Editor - Open File",
  5.             "/Users/luis/Documents/QT/Text Editor/",
  6.             "Text Files (*.txt);;All Files (*.*)"
  7.  
  8.          );

Fijate bien en la linea 4 de los 2 codigos anteriores.

en el codigo es la linea 136
Tutoriales de Qt C++

No es necesario que hagamos Grandes cosas, sino que lo que hagamos sea importante.

SI la NECESIDAD es la MADRE del CONOCIMIENTO, SEGURAMENTE la PEREZA su TÍA.

Cuando el ARTE requiere de PRECISION le llamamos CIENCIA

Desconectado bigluis

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 511
    • Tutoriales de Qt C++
Re: Video Tutorial Programación Qt C++
« Respuesta #44 en: 07 de Mayo de 2013, 18:52:10 »
Por cierto, olvide mencionar que el codigo anterior contiene errores porque estuve jugnado con un componente que se llama QScintilla que es basicamente un editor de codigo. Este es el que utilizan la mayoria de editores de codigo libre

http://www.scintilla.org/


http://www.riverbankcomputing.com/software/qscintilla/intro

http://en.wikipedia.org/wiki/Scintilla_%28editing_component%29

 :oops: :oops: :oops:

A continuacion envio el codigo sin errores
Tutoriales de Qt C++

No es necesario que hagamos Grandes cosas, sino que lo que hagamos sea importante.

SI la NECESIDAD es la MADRE del CONOCIMIENTO, SEGURAMENTE la PEREZA su TÍA.

Cuando el ARTE requiere de PRECISION le llamamos CIENCIA