首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Qshow分割故障

Qshow分割故障
EN

Stack Overflow用户
提问于 2010-12-19 05:35:27
回答 1查看 1.2K关注 0票数 16
代码语言:javascript
复制
  setText mb $ "Hello World"
  qshow mb () -- Segmentation Failt 
  --print ("Hello world") -- it works

我使用的是qtHaskell,但我在这里发现的跟踪示例的唯一问题是qshow分段错误。

也许有人有任何想法,我该如何尝试修复它?

谢谢。

新增:完整程序代码:

代码语言:javascript
复制
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日志

代码语言:javascript
复制
> > ncdy@Cndy ~/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

添加: build命令

代码语言:javascript
复制
ghc --make -package qt -fglasgow-exts -O2 -o a HCK.hs -i

@Foo Bah这个问题是在12月18日被问到的,我不能确定我的答案是什么,但是操作系统是Windows7,告诉我关于这个系统我到底能说些什么?

@Vlad Lazarenko我知道,但这肯定是windows )

使用cygwin的@Foo Bah,嗯?我需要在哪里使用它?我在这台机器上,我可以再次尝试qtHaskell并检查当前情况,但我猜还会有其他版本。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-02-23 21:47:41

在您的示例中,有几个点可能会造成麻烦。我在这里强调的是,处理内存问题可能非常依赖于您使用哪个库来进行内存管理。

首先,您需要通知qtHaskell何时应该运行垃圾收集。我会把它放在on_hello_clicked例程的末尾。适当的调用是returnGC。在main函数的末尾放置另一个returnGC调用也是一个好主意。

其次,您的main函数指定了一个不存在的整数参数。应将main指定为main :: IO ()

因此,完整的代码将是:

代码语言:javascript
复制
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

它在WindowsXP + Cygwin和MacOS 10.6上编译和运行得很好

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4480293

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档