2010-12-18 13 views
17
setText mb $ "Hello World" 
    qshow mb() -- Segmentation Failt 
    --print ("Hello world") -- it works 

Estoy usando qtHaskell pero el único problema que encontré aquí es la falla de segmentación de qshow.Qshow Segmentation Fault

¿Puede alguien tener alguna idea de cómo puedo tratar de solucionarlo?

gracias.

añadido: completa el código del programa:

module Main where 

import Qtc.Classes.Qccs 
import Qtc.Classes.Gui 
import Qtc.ClassTypes.Gui 
import Qtc.Core.Base 
import Qtc.Gui.Base 
import Qtc.Gui.QApplication 
import Qtc.Gui.QWidget 
import Qtc.Gui.QPushButton 
import Qtc.Gui.QAbstractButton 
import Qtc.Gui.QMessageBox 

type MyQPushButton = QPushButtonSc (CMyQPushButton) 
data CMyQPushButton = CMyQPushButton 

myQPushButton :: String -> IO (MyQPushButton) 
myQPushButton b = qSubClass $ qPushButton b 

main :: IO Int 
main = do 
    qApplication() 
    hello <- myQPushButton "Hello qtHaskell World" 
    resize hello (200::Int, 60::Int) 
    mb <- qMessageBox hello 
    connectSlot hello "clicked()" hello "click()" $ on_hello_clicked mb 
    qshow hello() 
    qApplicationExec() 

on_hello_clicked :: QMessageBox() -> MyQPushButton -> IO() 
on_hello_clicked mb this 
    = do 
    tt <- text this() 
    setText mb $ "You have clicked " ++ tt 
    qshow mb() 

valgrind añadido registro

> > [email protected] ~/Haskell $ valgrind ./a 
> ==13467== Memcheck, a memory error detector 
> ==13467== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. 
> ==13467== Using Valgrind-3.6.0 and LibVEX; rerun with -h for copyright 
> info 
> ==13467== Command: ./a 
> ==13467== 
> 
> ==13467== Syscall param writev(vector[...]) points to 
> uninitialised byte(s) 
> ==13467== at 0x40008D2: ??? (in /lib/ld-2.11.2.so) 
> ==13467== Address 0x6e85d97 is 2,703 bytes inside a block of size 16,384 
> alloc'd 
> ==13467== at 0x4027834: calloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) 
> ==13467== by 0x69C4BD4: XOpenDisplay (in 
> /usr/lib/libX11.so.6.3.0) 
> ==13467== by 0x4C505F53: ??? 
> ==13467== 
> ==13467== 
> ==13467== Process terminating with default action of signal 11 (SIGSEGV) 
> ==13467== General Protection Fault 
> ==13467== at 0x5957480: ??? (in /usr/lib/qt4/libQtGui.so.4.7.1) 
> ==13467== by 0x5B5FD81: ??? (in /usr/lib/qt4/libQtGui.so.4.7.1) 
> ==13467== by 0x5B6BC19: ??? (in /usr/lib/qt4/libQtGui.so.4.7.1) 
> ==13467== by 0x5B71B3C: ??? (in /usr/lib/qt4/libQtGui.so.4.7.1) 
> ==13467== by 0x5AE757D: QPainter::drawPixmap(QRectF const&, 
> QPixmap const&, QRectF const&) (in 
> /usr/lib/qt4/libQtGui.so.4.7.1) 
> ==13467== by 0xA71AA68: Oxygen::Helper::renderWindowBackground(QPainter*, 
> QRect const&, QWidget const*, QWidget 
> const*, QColor const&, int, int) (in 
> /usr/lib/liboxygenstyle.so.4.5.0) 
> ==13467== Invalid free()/delete/delete[] 
> ==13467== at 0x402868B: free (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so) 
> ==13467== by 0x52F78DB: ??? (in /lib/libc-2.11.2.so) 
> ==13467== by 0x105FFFF: ??? 
> ==13467== Address 0x5133a98 is not stack'd, malloc'd or (recently) free'd 
> ==13467== 
> ==13467== 
> ==13467== HEAP SUMMARY: 
> ==13467==  in use at exit: 1,968,209 bytes in 27,864 blocks 
> ==13467== total heap usage: 65,595 allocs, 37,732 frees, 6,175,162 bytes 
> allocated 
> ==13467== 
> ==13467== LEAK SUMMARY: 
> ==13467== definitely lost: 18,054 bytes in 259 blocks 
> ==13467== indirectly lost: 94,591 bytes in 628 blocks 
> ==13467==  possibly lost: 489,039 bytes in 5,656 blocks 
> ==13467== still reachable: 1,366,525 bytes in 21,321 blocks 
> ==13467==   suppressed: 0 bytes in 0 blocks 
> ==13467== Rerun with --leak-check=full to see details of leaked memory 
> ==13467== 
> ==13467== For counts of detected and suppressed errors, rerun with: -v 
> ==13467== Use --track-origins=yes to see where uninitialised values come 
> from 
> ==13467== ERROR SUMMARY: 3 errors from 2 contexts (suppressed: 15 from 8) 
> Segmentation fault 

añadido: construir comando

ghc --make -package qt -fglasgow-exts -O2 -o a HCK.hs -i 

@foo Bah la pregunta fue hecha el 18 de diciembre , No puedo estar seguro con mis respuestas, pero el sistema operativo era Windows7, dime, ¿qué puedo decir exactamente sobre el sistema?

@Vlad Lazarenko sé, pero era seguro para ventanas)

@foo Bah Uso de cygwin, eh? Donde necesito usarlo? Estoy en esta máquina y puedo hacer otra prueba para qtHaskell y verificar la situación actual, pero supongo que habrá otras versiones.

+0

¿Cuál es su programa completo? ¿Cómo se define 'mb'? ¿Estás llamando 'qApplication()' primero? – luqui

+0

Hmm, estás haciendo todo lo que los doctores dicen que haga ... Estoy perplejo. – luqui

+1

Tu código funcionó bien, el botón y el diálogo estaban bien. Probado en ghc 6.10.4; dev-haskell/qt-1.1.4; x11-libs/qt-gui-4.6.2; dev-haskell/cabal-1.8.0.6. Reconstruir QtHaskell puede solucionar su problema. Espero que tengas más de 1G de RAM; Me tomó cuatro días construir en 1G debido a la paginación. – frayser

Respuesta

1

Hay un par de puntos que pueden causar problemas en su ejemplo. Enfatizo que aquí, como ocuparse de los problemas de memoria puede ser muy dependiente de qué biblioteca tiene su gestión de memoria.

En primer lugar, querrá notificar a qtHaskell cuando se debería ejecutar la recolección de basura. Yo colocaría esto al final de su rutina on_hello_clicked. La llamada apropiada es returnGC. También es una buena idea realizar otra llamada returnGC al final de su función main.

En segundo lugar, su función principal es especificar un parámetro entero que no existe. Se debe especificar como mainmain :: IO()

Por lo tanto, el código completo sería:

module Main where 

import Qtc.Classes.Qccs 
import Qtc.Classes.Gui 
import Qtc.ClassTypes.Gui 
import Qtc.Core.Base 
import Qtc.Gui.Base 
import Qtc.Gui.QApplication 
import Qtc.Gui.QWidget 
import Qtc.Gui.QPushButton 
import Qtc.Gui.QAbstractButton 
import Qtc.Gui.QMessageBox 

type MyQPushButton = QPushButtonSc (CMyQPushButton) 
data CMyQPushButton = CMyQPushButton 

myQPushButton :: String -> IO (MyQPushButton) 
myQPushButton b = qSubClass $ qPushButton b 

main :: IO() 
main = do 
    qApplication() 
    hello <- myQPushButton "Hello qtHaskell World" 
    resize hello (200::Int, 60::Int) 
    mb <- qMessageBox hello 
    connectSlot hello "clicked()" hello "click()" $ on_hello_clicked mb 
    qshow hello() 
    qApplicationExec() 
    returnGC 

on_hello_clicked :: QMessageBox() -> MyQPushButton -> IO() 
on_hello_clicked mb this 
    = do 
    tt <- text this() 
    setText mb $ "You have clicked " ++ tt 
    qshow mb() 
    returnGC 

Esto compila y funciona muy bien en Windows XP + Cygwin, así como MacOS 10.6

Cuestiones relacionadas