Tsim ib qho app rau Ubuntu Kov [QML] - [Ntu 2]

Taw qhia:

Zoo ntawm no peb muaj tus ncej uas ua raws li cov thawj feemHauv qhov no peb yuav tsom mus rau kev tuav cov ntaub ntawv (cov lus nug), thiab peb yuav pib nrog lub cav qhov kev ua si, nyob rau tom ntej no peb yuav ua kom tiav cov cav thiab siv lub sijhawm thiab 3 txoj kev xaiv.

Koj tuaj yeem nrhiav cov cai nyob hauv kuv qhov chaw khaws khoom (Launchpad repository)nyem qhov no), qhov twg Kuv yuav hloov kho nws thaum kuv mus.

Cov Ntaub Ntawv:

Rau cov ntaub ntawv peb yuav siv U1db ua, uas yog ib qho chaw khaws ntaub ntawv uas khaws cov ntaub ntawv tawm hauv cov hom ntawv JSON.

Ua ntej tshaj plaws peb pom cov ntaub ntawv peb yuav tsum khaws tseg, peb muaj 1 lo lus nug (sib nrug ntawm cov ntawv ntawm cov lus nug nws yuav zoo yog tias muaj tus cim), nrog 4 cov lus teb tau, ntawm cov uas tsuas yog 1 tuaj yeem, yog li ntawd daim ntawv hauv JSON ib nqe lus nug yuav tsum yog:

{"id": 1, "lus nug": "yuav muaj dev.fromlinux.net", "lus teb": {r1: "yog", r2: "tsis tau", r3: "nws tsis paub", r4: "qhov no yog cov lus teb tsis tseeb "}," kho ": 3}

Raws li peb pom peb tau teeb tsa ua hom phiaj JSON qhov twg peb muaj tus cim, qhov hlua nrog cov nqe lus nug thiab r1, r2 uas sawv cev rau cov lus teb 1 thiab 2, thaum kawg peb muaj cov lus teb twg yog.

Cia peb pom me ntsis li cas U1db ua haujlwm, thawj qhov uas peb yuav tsum tau siv U1db yog los import qhov module:

import U1db 1.0 as U1db

Peb tshaj tawm cov ntaub ntawv:

U1db.Database {
id: aDatabase
path: "aU1DbDatabase"
}

Cov ntaub ntawv yuav khaws tseg ua aU1DbDatabase.u1db, tam sim no peb tsim daim ntawv:

U1db.Document {
id: aDocument
database: aDatabase
docId: 'helloworld'
create: true
defaults: { "hello": "Hello World!" }
}

Qhov twg peb tuaj yeem pom cov hom ntawv {«nyob zoo»: «ib yam dab tsi»}, kom ua cov lus nug, ib qho ntxiv cov ntaub ntawv, muab cov ntaub ntawv, lwv lawv thiab lwm yam. Peb muaj U1db.Query keeb.

Peb tuaj yeem nrhiav a tutorial nyob rau hauv kev txhim kho lub vev xaib ntawm Ubuntu.

Cia peb mus rau peb daim ntawv thov thiab tsim peb lub chaw khaws ntaub ntawv, raws li peb tau pom peb txhais lub chaw khaws ntaub ntawv:

U1db.Database {id: db lus nug; txoj kev: "questionsdb.u1db"}

Okay, tam sim no cia peb muab qee lub ntsiab lus tso rau hauv cov ntaub ntawv hauv database databasedb:

    U1db.Document {id: aDocument database: questionsdb docId: 'cov lus nug' tsim: cov ntsiab lus tsis raug: {"cov lus nug": [{"nug": "Puas yuav muaj dev.fromlinux.net?", "R1": "yog", " r2 ":" tsis muaj "," r3 ":" ntswg "," r4 ":" cov lus teb tsis tseeb "," kom raug ":" 3 "}, {" lus nug ":" Leej twg yog hagrid (harry potter)? "," r1 ":" Tus lwm thawj xib fwb ntawm lub tsev kawm ntawv "," r2 ":" Tus ranger "," r3 ":" Tus xib fwb ntawm kev hloov pauv "," r4 ":" Ib pawg "," muaj tseeb ":" 2 "}, { "lus nug": "Dab tsi yog peev ntawm Iceland?", "r1": "Amsterdam", "r2": "Reykjavik", "r3": "Tbilisi", "r4": "Almaty", "raug" : "2"}]}}

Kuv paub tias qhov code ntawd tsis tshwm li nws yuav tsum, tab sis yog tias peb saib peb yuav pom tias peb muaj lub caij nyoog questioning, uas nrog cov ["]" peb qhia meej tias yuav muaj ntau qhov (lawv tsis zoo li qub) cov ntsiab lus; qhov no peb yuav muaj 4 los ntawm lub neej ntawd, 4 lus nug nrog lawv cov lus teb.

Txhawm rau txais cov ntawv hais JSON, peb tuaj yeem qhia lub cim ntawm cov ntaub ntawv uas peb tau tsim (uas yog cov ntaub ntawv keeb kwm)). Cia peb xav tias peb xav tau txais cov ntawv ntawm thawj lo lus nug:

aDocument.contents.questions [0] .iskas

Cov kab ntawm cov lej no xa rov qab rau cov lus nug cov ntsiab lus ntawm daim ntawv aDocument, ntawm 0 1 (thawj ntawm qhov ntsuas), uas yog: «Puas yuav muaj dev.fromlinux.net?». Yog tias peb ntsuas tus lej XNUMX, ces nws mus rau lo lus nug thib ob.

Kev tsim cov txiaj ntsig kev ua si

Zoo, tam sim no peb paub tias yuav ua li cas thiaj lis pov thawj cov chaw khaws ntaub ntawv uas peb tau khaws cov lus nug, peb tab tom ua haujlwm rau qhov laj thawj ntawm qhov kev ua si. Ua ntej tshaj plaws peb yuav tsim cov ntawv JavaScript (.js): Ntxiv tshiab -> Qt -> Js Cov Ntaub Ntawv. Kuv yuav hu nws logic.js.

Hauv cov ntaub ntawv peb yuav tsim los ua ob peb lub zog, kom import js ntawv rau hauv peb daim ntawv qml:

import "logica.js" ua Logica

Peb koom lub npe Logica, yog li ntawd thaum peb xav hu ua haujlwm peb yuav ua nws li Logica.funcion (), zoo li nws yog ib qho khoom siv uas muaj nws txoj hauv kev.

Txog tam sim no, yog li ntawv tshaj tawm tsis dhau mus ntev, peb yuav tawm lub sijhawm ntawm cov lus nug thiab cov kev xaiv rau tom qab, peb yuav mloog zoo rau cov lus nug thiab cov ntsiab lus, cia pom ib txoj haujlwm uas peb yuav siv los hloov ntawm lo lus nug:

muaj nuj nqi nextQuestion (tooj) {// sij hawm = 0 nqe lus nug.text = aDocument.contents.questions [num] .question; resp1.text = aDocument.contents.questions [tooj] .r1; resp2.text = aDocument.contents.questions [num] .r2; resp3.text = aDocument.contents.questions [tooj] .r3; resp4.text = aDocument.contents.questions [num] .r4; }

Raws li peb tuaj yeem pom, peb dhau tus lej nug xov tooj qhov chaw uas peb muaj kev sib cav thiab los ntawm no nws muab cov lus teb rau cov nyees khawm thiab cov lus nug lo. Tam sim no pom tam sim no los siv tau yog tias cov lus teb raug xaiv:

muaj nuj nqi ntaus (tooj, xaiv) {var ntaus = cuav; var num_correcto = aDocument.contents.questions [tooj] .correcto; yog tias (xaiv == correct_num) ntaus = tseeb; rov qab ntaus; }

Txoj cai hais lus rau nws tus kheej, yog hais tias cov kev xaiv uas xaiv tau yog tib yam li qhov uas tau muab los ntawm cov ntaub ntawv, ces nws yuav yog qhov tseeb, txwv tsis pub nws yuav tsis yog. Tam sim no peb muaj cov haujlwm no tau txhais, peb yuav siv lawv hauv peb cov lej qml.

Ua ntej tshaj plaws peb yuav ntxiv qhov sib txawv uas yuav yog tus tswj hwm cov lus nug uas peb nyob hauv, peb yuav hu nws tus lej; Peb tseem yuav muaj peb lub zog ntxiv: ntaus, ploj thiab ntsiab lus.

    cov khoom muaj menyuam tus lej: 0 cov khoom lag luam int nfaults: 0 khoom ntiag tug rau cov menyuam muaj hnub yug: 0 khoom ntiag tug rau cov tshuaj ntsuam: 0

Thaum pib lawv muaj tag nrho ntawm 0.

Tam sim no peb ntxiv onClick rau tag nrho cov khawm teb. onClick, raws li nws lub npe hais tias, yog ib qho kev tshwm sim uas yuav tshwm sim thaum lub pob nyem:

            Khawm {id: resp1 ntawv nyeem: "Teb lus 1" anchors.hor HorizontalCenter: parent.hor HorizontalCenter qhov dav: parent.width - 20 onClicked: {yog (Logic. meej (tus lej, 1)) {tooj = tooj + 1; Logic.nextQuestion (num) npoints = ntsuas + 50 yug = = yug + 1} lwm {nfaults = nfaults + 1}}}

Peb pom tias thaum koj nyem lub pob, nws xyuas yog tias nws yog lossis tsis yog, yog tias nws yog, ntxiv cov ntsiab lus thiab dhau cov lus nug, txwv tsis pub ib lub neej nyob.

Thaum kawg peb yuav ua thawj nqe lus nug thauj khoom thaum Nplooj Nplooj tivthaiv ntim:

    Nplooj ntawv {id: pageGame Cheebtsam.onCompleted: {Logic.nextPregunta (0)}

Saib seb nws muab tawm:

xeem


Cov ntsiab lus ntawm tsab xov xwm ua raws li peb cov ntsiab cai ntawm kev tswj hwm kev ncaj nceesCov. Tshaj tawm ib qho yuam kev nyem no.

2 lus, tawm koj li

Tso koj saib

Koj email chaw nyob yuav tsis tsum luam tawm.

*

*

  1. Lub luag haujlwm rau cov ntaub ntawv: Miguel Ángel Gatón
  2. Lub hom phiaj ntawm cov ntaub ntawv: Tswj SPAM, kev tswj xyuas tawm tswv yim.
  3. Sau raws cai: Koj kev tso cai
  4. Kev sib txuas lus ntawm cov ntaub ntawv: Cov ntaub ntawv yuav tsis raug xa mus rau lwm tus neeg thib peb tsuas yog los ntawm kev txiav txim siab raug cai.
  5. Cov ntaub ntawv khaws cia: Cov Ntaub Ntawv khaws tseg los ntawm Occentus Networks (EU)
  6. Txoj Cai: Txhua lub sijhawm koj tuaj yeem txwv, rov qab thiab tshem tawm koj cov ntaub ntawv.

  1.   Gabielus said

    Kuv ua raws cov kauj ruam thiab txhua yam ua haujlwm. Tsuas yog koom tes Kuv hais tias:
    * Tsis hloov pauv tus nqi ntawm kev mus ntsib thiab ploj. Koj yuav tsum ntxiv qhov ntawd rau txhua lub pob hauv koj qhov kev tshwm sim nias.
    * Thiab cov ntawd nyob hauv kab:
    yog tias (Logic.acerto (tooj, 1)) {
    Koj yuav tsum pauv 1 rau tus naj npawb ntawm lub pob / cov lus teb.

    lolbimbo, Kuv pom koj cov nyiaj pab nthuav. Kuv vam tias tshiab tutos !!!

    Tsaug rau sib qhia.

    1.    loj said

      Kuv nyiam tias koj tau hais txog cov ntsiab lus no vim tias kuv tsis tau hais meej hauv kev xa ntawv, dab tsi ntxiv, Kuv tsis nco qab cov ntsiab lus, qhov ua tiav thiab tsis ua tiav, yog tias koj saib ntawm koj koj yuav pom tias thaum peb nyem lub pob, peb ntxiv cov ntsiab lus ntawm cov kev ua tiav ... tab sis lawv tsis xav txog hauv Daim Ntawv, vim li ntawd peb yuav tsum muab nws tso rau hauv nws cov ntawv sau uas qhia cov ntsiab lus:

      Cim {
      id: swb
      ntawv nyeem: «Cov lus yuam kev:» + tsis zoo
      xim: "liab"
      }

      Cim {
      id: hits
      ntawv nyeem: «Hits:» + yug
      }

      Cim {
      id: ntsiab lus
      ntawv nyeem: «Cov ntsiab lus:» + npoints
      fontSize: "nruab nrab"
      }

      Kuv tseem yuav hais kom meej ntxiv nyob rau Ntu 3.