FU Logo
  • Startseite
  • Kontakt
  • Impressum
  • Home
  • Listenauswahl
  • Anleitungen

[linux-minidisc] Qt5 compatibility

thread -->
date -->
  • From: Thomas Arp <manner.moe@gmx.de>
  • To: "linux-minidisc@lists.fu-berlin.de" <linux-minidisc@lists.fu-berlin.de>
  • Date: Sun, 01 Dec 2013 23:29:45 +0100
  • Subject: [linux-minidisc] Qt5 compatibility

Hi,

i upgraded my windows build environment to Qt5 for testing.
I made some changes so that the code can be complied with Qt4 and Qt5.

Regards
Thomas

P.S.: Tested with Qt 4.7 and Qt 5.1 with gcc on Windows XP
>From 4619f10fc873f1c115f7c26258285e9a667bf135 Mon Sep 17 00:00:00 2001
From: Thomas Arp <manner.moe@gmx.de>
Date: Sun, 1 Dec 2013 20:26:00 +0100
Subject: [PATCH] Adaptations to make the code Qt5 compatible

---
 qhimdtransfer/main.cpp              |  2 +-
 qhimdtransfer/qhimdaboutdialog.h    |  2 +-
 qhimdtransfer/qhimdformatdialog.h   |  2 +-
 qhimdtransfer/qhimdmainwindow.cpp   | 10 +++++-----
 qhimdtransfer/qhimdmainwindow.h     |  4 ++--
 qhimdtransfer/qhimdmodel.cpp        |  6 ++++--
 qhimdtransfer/qhimdmodel.h          |  2 +-
 qhimdtransfer/qhimdtransfer.pro     |  4 ++++
 qhimdtransfer/qhimduploaddialog.h   |  2 +-
 qhimdtransfer/qhimdwindetection.cpp | 21 +++++++++++++++------
 10 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/qhimdtransfer/main.cpp b/qhimdtransfer/main.cpp
index 91ae588..e7a3e2f 100644
--- a/qhimdtransfer/main.cpp
+++ b/qhimdtransfer/main.cpp
@@ -1,4 +1,4 @@
-#include <QtGui/QApplication>
+#include <QApplication>
 #include <QtCore/QTranslator>
 #include <QtCore/QLocale>
 #include "qhimdmainwindow.h"
diff --git a/qhimdtransfer/qhimdaboutdialog.h b/qhimdtransfer/qhimdaboutdialog.h
index c7c8a5b..1ff4cda 100644
--- a/qhimdtransfer/qhimdaboutdialog.h
+++ b/qhimdtransfer/qhimdaboutdialog.h
@@ -1,7 +1,7 @@
 #ifndef QHIMDABOUTDIALOG_H
 #define QHIMDABOUTDIALOG_H
 
-#include <QtGui/QDialog>
+#include <QDialog>
 
 namespace Ui {
     class QHiMDAboutDialog;
diff --git a/qhimdtransfer/qhimdformatdialog.h b/qhimdtransfer/qhimdformatdialog.h
index 5b92c8a..d2bb04c 100644
--- a/qhimdtransfer/qhimdformatdialog.h
+++ b/qhimdtransfer/qhimdformatdialog.h
@@ -1,7 +1,7 @@
 #ifndef QHIMDFORMATDIALOG_H
 #define QHIMDFORMATDIALOG_H
 
-#include <QtGui/QDialog>
+#include <QDialog>
 
 namespace Ui {
     class QHiMDFormatDialog;
diff --git a/qhimdtransfer/qhimdmainwindow.cpp b/qhimdtransfer/qhimdmainwindow.cpp
index e2675d9..1b86651 100644
--- a/qhimdtransfer/qhimdmainwindow.cpp
+++ b/qhimdtransfer/qhimdmainwindow.cpp
@@ -2,8 +2,8 @@
 #include "ui_qhimdmainwindow.h"
 #include "qhimdaboutdialog.h"
 #include "qhimduploaddialog.h"
-#include <QtGui/QMessageBox>
-#include <QtGui/QApplication>
+#include <QMessageBox>
+#include <QApplication>
 
 #include <QtCore/QDebug>
 
@@ -282,8 +282,8 @@ bool QHiMDMainWindow::autodetect_init()
 {
     int k;
 
-    k = QObject::connect(detect, SIGNAL(himd_found(QString)), this, SLOT(himd_found(QString)));
-    k += QObject::connect(detect, SIGNAL(himd_removed(QString)), this, SLOT(himd_removed(QString)));
+    k = (bool)QObject::connect(detect, SIGNAL(himd_found(QString)), this, SLOT(himd_found(QString)));
+    k += (bool)QObject::connect(detect, SIGNAL(himd_removed(QString)), this, SLOT(himd_removed(QString)));
 
     if(!k)
         return false;
@@ -300,7 +300,7 @@ void QHiMDMainWindow::open_himd_at(const QString & path)
     QMessageBox himdStatus;
     QString error;
 
-    error = trackmodel.open(path.toAscii());
+    error = trackmodel.open(path.toLatin1());
 
     if (!error.isNull()) {
         himdStatus.setText(tr("Error opening HiMD data. Make sure you chose the proper root directory of your HiMD-Walkman.\n") + error);
diff --git a/qhimdtransfer/qhimdmainwindow.h b/qhimdtransfer/qhimdmainwindow.h
index 85be8ae..b9b14f7 100644
--- a/qhimdtransfer/qhimdmainwindow.h
+++ b/qhimdtransfer/qhimdmainwindow.h
@@ -1,8 +1,8 @@
 #ifndef QHIMDMAINWINDOW_H
 #define QHIMDMAINWINDOW_H
 
-#include <QtGui/QMainWindow>
-#include <QtGui/QFileDialog>
+#include <QMainWindow>
+#include <QFileDialog>
 #include <QtCore/QSettings>
 #include "qhimdaboutdialog.h"
 #include "qhimdformatdialog.h"
diff --git a/qhimdtransfer/qhimdmodel.cpp b/qhimdtransfer/qhimdmodel.cpp
index ac4bde5..9d8f4ed 100644
--- a/qhimdtransfer/qhimdmodel.cpp
+++ b/qhimdtransfer/qhimdmodel.cpp
@@ -232,8 +232,9 @@ QString QHiMDTracksModel::open(const QString & path)
         return QString::fromUtf8(status.statusmsg);
     }
     close();
+    beginResetModel();
     himd = newhimd;
-    reset();	/* inform views that the model contents changed */
+    endResetModel();	/* inform views that the model contents changed */
     return QString();
 }
 
@@ -247,9 +248,10 @@ void QHiMDTracksModel::close()
     struct himd * oldhimd;
     if(!himd)
         return;
+    beginResetModel();
     oldhimd = himd;
     himd = NULL;
-    reset();	/* inform views that the model contents changed */
+    endResetModel();	/* inform views that the model contents changed */
     himd_close(oldhimd);
     delete oldhimd;
 }
diff --git a/qhimdtransfer/qhimdmodel.h b/qhimdtransfer/qhimdmodel.h
index 6ccc2f8..65218c3 100644
--- a/qhimdtransfer/qhimdmodel.h
+++ b/qhimdtransfer/qhimdmodel.h
@@ -5,7 +5,7 @@
 #include <QtCore/QTime>
 #include <QtCore/QList>
 #include <QtCore/QStringList>
-#include <QtGui/QFileSystemModel>
+#include <QFileSystemModel>
 #include "himd.h"
 
 #include "sony_oma.h"
diff --git a/qhimdtransfer/qhimdtransfer.pro b/qhimdtransfer/qhimdtransfer.pro
index db12602..6d3e39d 100644
--- a/qhimdtransfer/qhimdtransfer.pro
+++ b/qhimdtransfer/qhimdtransfer.pro
@@ -5,6 +5,10 @@ TARGET = qhimdtransfer
 DEPENDPATH += .
 INCLUDEPATH += .
 
+# for Qt5 compatibility
+QT += gui
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
 # determine version number from git
 VERSION = $$system(sh ../get_version.sh)
 #    !isEmpty(VERSION){
diff --git a/qhimdtransfer/qhimduploaddialog.h b/qhimdtransfer/qhimduploaddialog.h
index 86bcd5c..157c58d 100644
--- a/qhimdtransfer/qhimduploaddialog.h
+++ b/qhimdtransfer/qhimduploaddialog.h
@@ -1,7 +1,7 @@
 #ifndef QHIMDUPLOADDIALOG_H
 #define QHIMDUPLOADDIALOG_H
 
-#include <QtGui/QDialog>
+#include <QDialog>
 #include "qhimdmodel.h"
 
 namespace Ui {
diff --git a/qhimdtransfer/qhimdwindetection.cpp b/qhimdtransfer/qhimdwindetection.cpp
index 1dc437a..3e79038 100644
--- a/qhimdtransfer/qhimdwindetection.cpp
+++ b/qhimdtransfer/qhimdwindetection.cpp
@@ -1,6 +1,6 @@
 #include <QtCore/QDebug>
 #include <QtCore/QList>
-#include <QtGui/QWidget>
+#include <QWidget>
 #include "qhimddetection.h"
 
 #define WINVER 0x0500
@@ -49,6 +49,7 @@ private:
     void remove_himd(HANDLE devhandle);
     HDEVNOTIFY register_mediaChange(HANDLE devhandle);
     void unregister_mediaChange(HDEVNOTIFY himd_change);
+    bool nativeEvent(const QByteArray & eventType, void * message, long *result);
     bool winEvent(MSG * msg, long * result);
 };
 
@@ -153,7 +154,7 @@ static bool is_himddevice(QString devID, QString & name)
     unsigned long buflen;
     QString recname, devicepath;
 
-    CM_Locate_DevNodeA(&devinst, devID.toAscii().data(), NULL);
+    CM_Locate_DevNodeA(&devinst, devID.toLatin1().data(), NULL);
     CM_Get_Parent(&devinstparent, devinst, NULL);
 
     if(devID.contains("RemovableMedia", Qt::CaseInsensitive))    // on Windows XP: get next parent device instance
@@ -201,7 +202,7 @@ void QHiMDWinDetection::add_himddevice(QString path, QString name)
     STORAGE_DEVICE_NUMBER sdn;
     OFSTRUCT OFfile;
 
-    drv[4] = path.at(0).toAscii();
+    drv[4] = path.at(0).toLatin1();
 
     hdev = CreateFileA(drv, NULL , FILE_SHARE_READ, NULL,
                                            OPEN_EXISTING, 0, NULL);
@@ -223,7 +224,7 @@ void QHiMDWinDetection::add_himddevice(QString path, QString name)
     new_device->path = path;
     new_device->recorder_name = name;
 
-    file[0] = path.at(0).toAscii();
+    file[0] = path.at(0).toLatin1();
     if(OpenFile(file, &OFfile, OF_EXIST) != HFILE_ERROR)
     {
         new_device->md_inserted = true;
@@ -301,7 +302,7 @@ HDEVNOTIFY QHiMDWinDetection::register_mediaChange(HANDLE devhandle)
     filter.dbch_handle = devhandle;
     filter.dbch_eventguid = my_GUID_IO_MEDIA_ARRIVAL;  // includes GUID_IO_MEDIA_REMOVAL notification
 
-    return RegisterDeviceNotification( this->winId(), &filter, DEVICE_NOTIFY_WINDOW_HANDLE);
+    return RegisterDeviceNotification( (HWND)this->winId(), &filter, DEVICE_NOTIFY_WINDOW_HANDLE);
 
 }
 
@@ -311,6 +312,14 @@ void QHiMDWinDetection::unregister_mediaChange(HDEVNOTIFY himd_change)
         UnregisterDeviceNotification(himd_change);
 }
 
+bool QHiMDWinDetection::nativeEvent(const QByteArray & eventType, void * message, long *result)
+{
+    if (eventType == "windows_generic_MSG")
+        return winEvent(reinterpret_cast<MSG*>(message), result);
+
+    return false;
+}
+
 bool QHiMDWinDetection::winEvent(MSG * msg, long * result)
     {
         QString name, devID, path ;
@@ -325,7 +334,7 @@ bool QHiMDWinDetection::winEvent(MSG * msg, long * result)
                     {
                         PDEV_BROADCAST_VOLUME pHdrv = (PDEV_BROADCAST_VOLUME)pHdr;
                         path = FindPath(pHdrv->dbcv_unitmask);
-                        devID = get_deviceID_from_driveletter(path.at(0).toAscii());
+                        devID = get_deviceID_from_driveletter(path.at(0).toLatin1());
                         if(!devID.isEmpty())
                         {
                             if(is_himddevice(devID, name))
-- 
1.8.4.msysgit.0

thread -->
date -->
  • Follow-Ups:
    • Re: [linux-minidisc] Qt5 compatibility
      • From: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
    • Re: [linux-minidisc] Qt5 compatibility
      • From: Michael Karcher <Michael.Karcher@fu-berlin.de>
  • linux-minidisc - December 2013 - Archives indexes sorted by:
    [ thread ] [ subject ] [ author ] [ date ]
  • Complete archive of the linux-minidisc mailing list
  • More info on this list...

Hilfe

  • FAQ
  • Dienstbeschreibung
  • ZEDAT Beratung
  • postmaster@lists.fu-berlin.de

Service-Navigation

  • Startseite
  • Listenauswahl

Einrichtung Mailingliste

  • ZEDAT-Portal
  • Mailinglisten Portal