コード例 #1
0
void MyClass::objectPush()
{
//! [sendfile]
// Create a transfer manager
QBluetoothTransferManager *transferManager = new QBluetoothTransferManager(this);

// Create the transfer request and file to be sent
QBluetoothAddress remoteAddress("00:11:22:33:44:55:66");
QBluetoothTransferRequest request(remoteAddress);
QFile *file = new QFile("testfile.txt");

// Ask the transfer manager to send it
QBluetoothTransferReply *reply = transferManager->put(request, file);
if (reply->error() == QBluetoothTransferReply::NoError) {

    // Connect to the reply's signals to be informed about the status and do cleanups when done
    QObject::connect(reply, SIGNAL(finished(QBluetoothTransferReply*)),
                     this, SLOT(transferFinished(QBluetoothTransferReply*)));
    QObject::connect(reply, SIGNAL(error(QBluetoothTransferReply::TransferError)),
                     this, SLOT(error(QBluetoothTransferReply::TransferError)));
} else {
コード例 #2
0
void RemoteSelector::on_sendButton_clicked()
{
    QBluetoothTransferManager mgr;
    QBluetoothTransferRequest req(m_service.device().address());

    m_file = new QFile(ui->fileName->text());

    Progress *p = new Progress;
    p->setStatus("Sending to: " + m_service.device().name(), "Waiting for start");
    p->show();

    QBluetoothTransferReply *reply = mgr.put(req, m_file);
    if(reply->error()){
        qDebug() << "Failed to send file";
        delete reply;
        p->finished(reply);
        return;
    }

    connect(reply, SIGNAL(uploadProgress(qint64,qint64)), p, SLOT(uploadProgress(qint64,qint64)));
    connect(reply, SIGNAL(finished(QBluetoothTransferReply*)), p, SLOT(finished(QBluetoothTransferReply*)));
    connect(p, SIGNAL(rejected()), reply, SLOT(abort()));
}