-1

I used the solution of below question for open file on Android.

Qt/Necessitas - reasonable QFileDialog replacement/skin?

But it works just on android,this codes (Qt Android Extras C++ Classes) don't run on windows?

for example i got the below errors?

#include<QAndroidJniObject>
#include<QtAndroid>
#include<QAndroidActivityResultReceiver>

Cannot open include file: 'QAndroidJniObject': No such file or directory

I used this for solving

#if defined(Q_OS_ANDROID)
#include<QAndroidJniObject>
#include<QtAndroid>
#include<QAndroidActivityResultReceiver>
#endif

but when i used this I have got another errors?

 class ResultReceiver:public QAndroidActivityResultReceiver//error :'QAndroidActivityResultReceiver': base class undefined
{
    AndroidFileDialog *_dialog;

public:
    ResultReceiver(AndroidFileDialog *dialog);

    virtual ~ResultReceiver();
    void handleActivityResult(int receiverRequestCode, int resultCode, const QAndroidJniObject &data);
    QString uriToPath(QAndroidJniObject uri);
};

'QAndroidActivityResultReceiver': base class undefined

Mohammad Kanan
  • 4,452
  • 10
  • 23
  • 47
mohsen
  • 1,763
  • 3
  • 17
  • 55
  • 1
    Mohsen, How do you expect a class part of Android Extras [QAndroidActivityResultReceiver](http://doc.qt.io/qt-5/qandroidactivityresultreceiver.html) to work under windows, – Mohammad Kanan Jul 18 '18 at 06:27
  • @MohammadKanan I want to run my application on android and windows.I want this solution for android ,and now it works,and i want to use `FileDialog` for windows.but how run my application on windows when i want to use this for android? – mohsen Jul 18 '18 at 08:00

2 Answers2

2

The class ResultReceiver inherits QAndroidActivityResultReceiver (from Android Extras) which you correctly stopped including for windows OS, thus the error.

You must have 2 variants of ResultReceiver class, one for Windows, another for Android. When you design it for Windows you should not inherit QAndroidActivityResultReceiver and use QFileDialog. In the same way you solved the import issues with Qt pre-processor, you could define ResultReceiver class , for example:
#if defined(Q_OS_ANDROID)

class AndroidFileDialog : public QObject
{
    Q_OBJECT
  ...
private:
    class ResultReceiver : public QAndroidActivityResultReceiver {
        AndroidFileDialog *_dialog;
        ...
    };
    ...
    ...
};
#else
class ResultReceiver // Here do not inherit classes from Android Extras
{
   QFileDialog *_dialog; // use standard Qt C++ classes 
   ...
   ...
};
#endif //Q_OS_ANDROID
Mohammad Kanan
  • 4,452
  • 10
  • 23
  • 47
1

That's understandable, the project is compiled in accordance with your *.pro file which includes all the project files. So you try to compile Android related files on Windows and so you get an error. You should include/exclude files in your *.pro file, according to the target OS, for example:

SOURCES += \
    common.cpp

HEADERS += \
    common.h

win32 {
    SOURCES += \
    winfile.cpp

    HEADERS += \
    winfile.h

    LIBS += -lwin
}

android {
    SOURCES += \
    androidfile.cpp

    HEADERS += \
    androidfile.h

    LIBS += -landroid
}

and so unnecessary files will not be compiled/linked

folibis
  • 12,048
  • 6
  • 54
  • 97
  • it still don't work ,i get `No such file or directory` error .and my project don't compile, – mohsen Jul 18 '18 at 13:40
  • "still don't work" says nothing about the problem. You probably did something wrong. Using conditionally including in .pro and preprocessor directives definitely can help. – folibis Jul 19 '18 at 05:50