Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppActions signal is not emitted ! #12

Open
majidkamali1370 opened this issue Dec 21, 2016 · 12 comments
Open

AppActions signal is not emitted ! #12

majidkamali1370 opened this issue Dec 21, 2016 · 12 comments

Comments

@majidkamali1370
Copy link

majidkamali1370 commented Dec 21, 2016

Hi @benlau
I want to use Flux in my app. I followed the guides, but I have a problem.
AppActions signal is not called at all !!!

in my view:

import "actions"
...
    onCheckedChanged: {
        if(checked)
            AppActions.selectContractor(contractorId)
        else
            AppActions.unselectContractor(contractorId)
    }
...

AppActions.qml

pragma Singleton

import QtQuick 2.7
import QuickFlux 1.0
import "."

ActionCreator {
    signal selectContractor(int cId);
    signal unselectContractor(int cId);
}

ActionTypes.qml

pragma Singleton

import QtQuick 2.7
import QuickFlux 1.0

KeyTable {
    id: actionTypes;
    property string selectContractor;
    property string unselectContractor;
}

my store:

pragma Singleton

import QtQuick 2.0
import QuickFlux 1.0
import "../actions"

AppListener {
    Filter {
        type: ActionTypes.selectContractor

        onDispatched: {
            console.log("selected contractor " + message.cId)
        }
    }
    Filter {
        type: ActionTypes.unselectContractor

        onDispatched: {
            console.log("unselected contractor " + message.cId)
        }
    }
}

But nothing is printed in console !!!
Even no error is reported
I have qmldirs files in actions and stores folders
What am I doing wrong?

Thanks

@benlau
Copy link
Owner

benlau commented Dec 21, 2016

Your code looks fine. Did you tried the example code in examples/ folder. Do it works? And what is your OS and Qt version?

@majidkamali1370
Copy link
Author

majidkamali1370 commented Dec 22, 2016

I checked both todo and photoalbum and both are working
Using Arch linux (kernel 4.4.5)
Qt 5.7.0 installed via offline installer

@benlau
Copy link
Owner

benlau commented Dec 23, 2016

I have no idea what was happening in your code. Do you mind to share your code to me?

@majidkamali1370
Copy link
Author

I can not share that with you, because it's not my own code, sorry :-(
But I explain you everything in code.
First, we have a utility library that we put useful and reusable components isnide it, I added QuickFlux in it and included pri file in library project pro file.
https:/benlau/quickflux#installation-instruction-without-qpm
I just changed quickflux.pri to QuickFlux.pri, nothing more :-)
Then, I imported QuickFlux version 1.0 into Qml files of main project.
Main project has following structure (inside project folder):

  • assets
    • qml
      • actions

        AppActions.qml
        ActionTypes.qml
        qmldir

      • stores

        ContractorInsertStore.qml
        SelectedContractorStore.qml
        qmldir

      • OTHER QML FILES

two stores are not related to eachother, so I did not create adapters folder and those files.
I first created SelectedContractorStore.qml and related ActionTypes and AppActions. When I tested it, It worked in a random way. sometimes with some parameters it worked, but sometime it did not.
When I added ContractorInsertStore.qml, none of them are working at all.

ActionTypes.qml full source code:

pragma Singleton

import QtQuick 2.0
import QuickFlux 1.0

KeyTable {
    id: actionTypes;

    property string changeHelp;
    property string selectContractor;
    property string unselectContractor;

    property string loadContractorFromDatabase;
    property string saveContractorToDatabase;
    property string setContractorMoshakhasat;
    property string setContractorTavanFanni;
    property string setContractorMali;
    property string setContractorTajhizat;
    property string setContractorSayer;

    property string removeContractorTavanFanniFromList;
    property string removeContractorTajhizatFromList;
    property string removeContractorSayerFromList;
}

qmldir in actions folder

singleton ActionTypes 1.0 ActionTypes.qml
singleton AppActions 1.0 AppActions.qml

qmldir in stores folder

singleton SelectedContractorsStore 1.0 SelectedContractorsStore.qml
singleton ContractorInsertStore 1.0 ContractorInsertStore.qml

AppActions.qml full source code:

pragma Singleton

import QtQuick 2.0
import QuickFlux 1.0
import "."

ActionCreator {
    signal changeHelp(string text, string state);

    signal selectContractor(int cId);
    signal unselectContractor(int cId);

    signal loadContractorFromDatabase(int cId);
    signal saveContractorToDatabase(int cId);
    signal setContractorMoshakhasat(var d);
    signal setContractorTavanFanni(var d);
    signal setContractorMali(var d);
    signal setContractorTajhizat(var d);
    signal setContractorSayer(var d);

    signal removeContractorTavanFanniFromList(int index);
    signal removeContractorTajhizatFromList(int index);
    signal removeContractorSayerFromList(int index);
}

In view, I've checked input parameter and they are valid.
Thanks :-)

@majidkamali1370
Copy link
Author

I have another question. Can I use this library in C++?
I mean e.i. create classes in c++ that act as stores, or AppActions etc

@majidkamali1370
Copy link
Author

I tested the code in windows with mingw compiler and Qt 5.7.0
Gives me following error:
qrc:/assets/qml/main.qml:4 module "QuickFlux" is not installed
I even called registerQuickFluxQmlTypes manually, but gives me that error again.

In linux, there is no error, but does not work.

PS: I had to add Q_DECL_EXPORT before QuickFlux class names.

@benlau
Copy link
Owner

benlau commented Dec 24, 2016

First, we have a utility library that we put useful and reusable components isnide it, I added QuickFlux in it and included pri file in library project pro file.

Do you mean to use QuickFlux in a plugin library?

I mean e.i. create classes in c++ that act as stores, or AppActions etc

QFAppDispatcher is the C++ implementation of AppDispatcher. It is possible to send and receive action message in C++. Moreover, it has an utility function , QFAppDispatcher::singletonObject(), to obtain the instance of QML singleton object from C++ . So the answer should be possible, but I am not sure is it a good approach.

I usually just declare AppActions / stores in QML. Then obtain the instance by the singletonObject() in C++

QFAppDispatcher Class | QuickFlux 1.0

@majidkamali1370
Copy link
Author

majidkamali1370 commented Dec 24, 2016

Do you mean to use QuickFlux in a plugin library?

It's not a plugin, but a simple Shared library. In main project, I added library via right clicking in .pro file and selecting 'Add Library', then selecting .so file path and include folder of that library.

@benlau
Copy link
Owner

benlau commented Dec 25, 2016

I never tried to use it in a shared library but I don't see any reason that not able to do so. Any chance that you have two QQmlEngine instance running?

@majidkamali1370
Copy link
Author

I don't think so. I use QQmlApplicationEngine.

...
QQmlApplicationEngine engine;
engine.addImageProvider("manpower", new ManPowerImageProvider());
engine.addImageProvider("slideshow", new SlideShowImageProvider());
engine.rootContext()->setContextProperty("DB", db);
engine.load(QUrl(QStringLiteral("qrc:/assets/qml/main.qml")));
return app.exec();

That's what I have done with QQmlApplicationEngine. (in main function)

@benlau
Copy link
Owner

benlau commented Dec 25, 2016

Then I have no idea what is the problem. Sorry

@majidkamali1370
Copy link
Author

I included pri file in main project file to use QuickFlux directly in my project, but it does not work neither.
It should be a serious problem in my code.
Excuse me for bothering you.
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants