Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. Spanish
  4. Salida standard no hace nada
Forum Updated to NodeBB v4.3 + New Features

Salida standard no hace nada

Scheduled Pinned Locked Moved Spanish
2 Posts 1 Posters 1.9k Views 1 Watching
  • 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.
  • O Offline
    O Offline
    oggie
    wrote on last edited by
    #1

    Hola,

    Soy nuevo en esto y trato de aprender. He buscado un ejemplo en internet que vuelca el contenido de una tabla MySQL en la consola (salida standard).

    Este es mi código,

    @
    #include <QtCore/QCoreApplication>
    #include <QtSql>
    // #include <qtextstream.h>
    #include <QTextStream>
    #include <QString>
    #include <iostream>

    using namespace std;

    int main(int argc, char *argv[]) {
    QCoreApplication a(argc, argv);
    //--- use a QTextStream: it makes it easier to output ---
    //--- QString to cout. ---
    QTextStream cout(stdout, QIODevice::WriteOnly);

    //--- define the database connection ---
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");  // host
    db.setDatabaseName("QtDummy");            // database
    db.setUserName("miuser");                // user
    db.setPassword("mipass");               // password
    
    //--- attempt to open it ---
    bool ok = db.open();
    
    if ( ok ) {
        //--- we're good! ---
        cout << "Database open\n";
    
        //--- run a query and print data returned ---
        QSqlQuery query( "select * from dummy" );
        if ( !query.isActive() )
            cout << "Query Error" + query.lastError().text()
                 << endl;
        else while (query.next()) {
                int Id = query.value(0).toInt();
                QString word = query.value(1).toString();
                cout << QString( "%1\t%2\n").arg( Id ).arg( word );
                }
    
        //--- add a new entry to the table ---
        query.prepare( "INSERT INTO dummy (word) VALUES ( :word )" );
        query.bindValue( ":word", "Banana" );
        query.exec&#40;&#41;;
    
        //--- close connection to database
        db.close();
    }
    else {
        //--- something went wrong ---
        cout << "Error opening database\n";
    }
    
    return 0;
    

    }
    @

    La questión es que no sale nada, ni mensaje de warning,
    ni mensaje de error ni resultados en la consulta.

    He comentado el código y poner solo cout << "Hola mundo\n" y tampoco
    sale nada.

    Trabajo con Qt Creator 2.4.1 en Ubuntu 12.04.

    Gracias de antemano,
    oggie

    1 Reply Last reply
    0
    • O Offline
      O Offline
      oggie
      wrote on last edited by
      #2

      Aquí está la respuesta a mi problema,

      "Configurar terminal":http://qt-project.org/forums/viewthread/17650

      Con esto ya funciona bien.

      Un saludo,
      oggie

      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